20260409

[Selenium]Microsoft Edge for macOSのWeb Driverのインストール

[Selenium]Microsoft Edge for macOSのWeb Driverのインストール

NOTE記事一覧ですnote.com

【スクリプトエディタで開く】 |

3_インストールWEB DRIVER.scpt
ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003(*
004web ドライバーのバージョンを揃える
005
006インストール先は
007/Users/ユーザーID/Library/Application Support/bin/edgedriver_mac64_m1
008
009https://github.com/MicrosoftEdge/EdgeWebDriver
010
011v1 初回作成
012v1.1 インテル対応
013
014com.cocolog-nifty.quicktimer.icefloe *)
015----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
016use AppleScript version "2.8"
017use framework "Foundation"
018use framework "UniformTypeIdentifiers"
019use framework "AppKit"
020use scripting additions
021property refMe : a reference to current application
022
023######################
024#設定項目 
025#モバイル端末偽装なら true 
026#通常PC画面サイズなら false
027set boolMoby to true as boolean
028
029
030######################
031#バンドルID
032set strBundleID to ("com.microsoft.edgemac") as text
033#NSBUNDLE
034set ocidAppBundle to (refMe's NSBundle's bundleWithIdentifier:(strBundleID))
035if ocidAppBundle ≠ (missing value) then
036   set ocidAppPathURL to ocidAppBundle's bundleURL()
037else if ocidAppBundle = (missing value) then
038   #NSWorkspace
039   set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
040   set ocidAppPathURL to (appSharedWorkspace's URLForApplicationWithBundleIdentifier:(strBundleID))
041end if
042#ここでアプリケーションが見つからなければ選択する
043if ocidAppPathURL = (missing value) then
044   set appFileManager to refMe's NSFileManager's defaultManager()
045   set ocidForDir to (refMe's NSApplicationDirectory)
046   set ocidInDomain to (refMe's NSUserDomainMask)
047   set ocidURLsArray to (appFileManager's URLsForDirectory:(ocidForDir) inDomains:(ocidInDomain))
048   set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
049   set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
050   set listUTI to {"com.apple.application-bundle"} as list
051   set strMsg to ("アプリケーション" & strBundleID & "を選択してください") as text
052   set strPrompt to ("アプリケーション" & strBundleID & "を選択してください") as text
053   try
054      tell application "SystemUIServer"
055         activate
056         set aliasFilePath to (choose file strMsg with prompt strPrompt default location (aliasDefaultLocation) of type listUTI with invisibles without showing package contents and multiple selections allowed) as alias
057      end tell
058   on error strErrMes number numErrNo
059      log strErrMes & numErrNo
060      return false
061   end try
062   set strAppPath to POSIX path of aliasFilePath as text
063   set strAppPathStr to refMe's NSString's stringWithString:(strAppPath)
064   set strAppPath to strAppPathStr's stringByStandardizingPath()
065   set ocidAppPathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(strAppPath) isDirectory:(true)
066end if
067#
068set ocidAppBinPathURL to ocidAppPathURL's URLByAppendingPathComponent:("Contents/MacOS/Microsoft Edge") isDirectory:(false)
069set ocidAppBinPath to ocidAppBinPathURL's |path|()
070#
071set ocidAppBundle to refMe's NSBundle's alloc()'s initWithURL:(ocidAppPathURL)
072#   set ocidInfoDict to ocidAppBundle's infoDictionary()
073#   set ocidAppVersion to ocidInfoDict's objectForKey:("CFBundleVersion")
074set ocidAppVersion to ocidAppBundle's objectForInfoDictionaryKey:("CFBundleVersion")
075
076
077
078#######################################################
079set recordSystemInfo to (system info) as record
080set strArt to (CPU type of recordSystemInfo) as text
081#バイナリー保存先
082set appFileManager to refMe's NSFileManager's defaultManager()
083set ocidForDir to (refMe's NSApplicationSupportDirectory)
084set ocidInDomain to (refMe's NSUserDomainMask)
085set ocidURLsArray to (appFileManager's URLsForDirectory:(ocidForDir) inDomains:(ocidInDomain))
086set ocidAppSupportDirPathURL to ocidURLsArray's firstObject()
087#
088if strArt contains "ARM" then
089   set ocidBinDirPathURL to ocidAppSupportDirPathURL's URLByAppendingPathComponent:("bin/edgedriver_mac64_m1") isDirectory:(true)
090else
091   set ocidBinDirPathURL to ocidAppSupportDirPathURL's URLByAppendingPathComponent:("bin/edgedriver_mac64") isDirectory:(true)
092end if
093set appFileManager to refMe's NSFileManager's defaultManager()
094set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s init()
095ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
096set listDone to appFileManager's createDirectoryAtURL:(ocidBinDirPathURL) withIntermediateDirectories:(true) attributes:(ocidAttrDict) |error|:(reference)
097#バイナリー
098set ocidBinFilePathURL to ocidBinDirPathURL's URLByAppendingPathComponent:("msedgedriver") isDirectory:(true)
099#有無確認
100set ocidBinFilePath to ocidBinFilePathURL's |path|()
101set boolDirExists to appFileManager's fileExistsAtPath:(ocidBinFilePath) isDirectory:(true)
102if boolDirExists is true then
103   set strCmd to ("/bin/zsh -c 'STR_STDOUT=$(\"" & ocidBinFilePath & "\" --version);LIST_OUT=(${=STR_STDOUT});STR_VER=${LIST_OUT[4]};/bin/echo ${STR_VER};'") as text
104   set strStdOut to (do shell script strCmd) as text
105   if strStdOut is (ocidAppVersion as text) then
106      set boolVersion to true
107   else
108      set boolVersion to false
109   end if
110else
111   set boolVersion to false
112end if
113
114if boolVersion is false then
115   #
116   set appFileManager to refMe's NSFileManager's defaultManager()
117   set listDone to (appFileManager's trashItemAtURL:(ocidBinFilePathURL) resultingItemURL:(ocidBinFilePathURL) |error|:(reference))
118   if strArt contains "ARM" then
119      set strURL to ("https://msedgedriver.microsoft.com/" & ocidAppVersion & "/edgedriver_mac64_m1.zip") as text
120   else
121      set strURL to ("https://msedgedriver.microsoft.com/" & ocidAppVersion & "/edgedriver_mac64.zip") as text
122   end if
123   set ocidURLString to refMe's NSString's stringWithString:(strURL)
124   set ocidURL to refMe's NSURL's alloc()'s initWithString:(ocidURLString)
125   #ディレクトリ
126   set appFileManager to refMe's NSFileManager's defaultManager()
127   set ocidTempDirURL to appFileManager's temporaryDirectory()
128   set ocidUUID to refMe's NSUUID's alloc()'s init()
129   set ocidUUIDString to ocidUUID's UUIDString
130   set ocidSaveDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:(true)
131   ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
132   set listDone to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:(true) attributes:(ocidAttrDict) |error|:(reference)
133   #パス
134   if strArt contains "ARM" then
135      set strFileName to "edgedriver_mac64_m1.zip" as text
136   else
137      set strFileName to "edgedriver_mac64.zip" as text
138   end if
139   set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strFileName) isDirectory:(false)
140   #NSDATA
141   set ocidOption to (refMe's NSDataReadingMappedIfSafe)
142   set listResponse to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidURL) options:(ocidOption) |error|:(reference)
143   set ocidReadData to (item 1 of listResponse)
144   #NSDATA
145   set ocidOption to (refMe's NSDataWritingAtomic)
146   set listDone to ocidReadData's writeToURL:(ocidSaveFilePathURL) options:(ocidOption) |error|:(reference)
147   set ocidSaveFilePath to ocidSaveFilePathURL's |path|()
148   set ocidBinDirPath to ocidBinDirPathURL's |path|()
149   set strCmd to ("/usr/bin/ditto -x -k \"" & ocidSaveFilePath & "\" \"" & ocidBinDirPath & "\"")
150   log (do shell script strCmd)
151   
152   ##ZIPファイルはゴミ箱へ入れる
153   set listDone to (appFileManager's trashItemAtURL:(ocidSaveDirPathURL) resultingItemURL:(ocidSaveDirPathURL) |error|:(reference))
154   
155end if
156
157
158
159set strPy to ("#!/usr/bin/env python3" & linefeed & "#coding: utf-8" & linefeed & "import os" & linefeed & "import subprocess" & linefeed & "import time" & linefeed & "import datetime" & linefeed & "from selenium import webdriver" & linefeed & "from selenium.webdriver.edge.service import Service" & linefeed & "from selenium.webdriver.edge.options import Options" & linefeed & "from selenium.webdriver.common.by import By" & linefeed & "from selenium.webdriver.support.ui import WebDriverWait" & linefeed & "from selenium.webdriver.support import expected_conditions as EC" & linefeed & linefeed & "# パス設定" & linefeed & "driver_path = os.path.expanduser(\"" & ocidBinFilePath & "\")" & linefeed & "edge_bin_path = os.path.expanduser(\"" & ocidAppBinPath & "\")" & linefeed & "tmp_dir_path = os.environ[\"TMPDIR\"]" & linefeed & "user_data_path = os.path.join(tmp_dir_path, \"Microsoft Edge Driver\")" & linefeed & "if not os.path.exists(user_data_path):" & linefeed & tab & "os.makedirs(user_data_path, exist_ok=True)" & linefeed & "os.chdir(user_data_path)" & linefeed & linefeed & "capture_dir_path = os.path.expanduser(\"~/Pictures/ScreenCapture/ScreenCapture\")" & linefeed & "if not os.path.exists(capture_dir_path):" & linefeed & tab & "os.makedirs(capture_dir_path, exist_ok=True)" & linefeed & linefeed & "options = Options()" & linefeed & "options.add_argument(f\"--user-data-dir={user_data_path}\")" & linefeed & "options.binary_location = edge_bin_path" & linefeed & linefeed & linefeed & "options.add_argument(\"--headless=new\")" & linefeed & "options.add_argument(\"--disable-gpu\")" & linefeed & "options.add_argument(\"--window-size=1920,1080\")" & linefeed & linefeed & linefeed & "service = Service(executable_path=driver_path)" & linefeed & "driver = webdriver.Edge(service=service, options=options)" & linefeed & linefeed & "wait = WebDriverWait(driver, 15)" & linefeed & "driver.get(\"https://note.com/\")" & linefeed & "wait.until(EC.presence_of_element_located((By.TAG_NAME, \"a\")))" & linefeed & "time.sleep(5)" & linefeed & linefeed & "print(f\"アクセス完了: {driver.title}\")" & linefeed & linefeed & "list_elements = driver.find_elements(By.TAG_NAME, \"a\")" & linefeed & "for item_element in list_elements:" & linefeed & tab & "str_url = item_element.get_attribute(\"href\")" & linefeed & tab & "str_link_text = item_element.text.strip()" & linefeed & tab & "if str_link_text:" & linefeed & tab & tab & "print(str_link_text)" & linefeed & tab & tab & "print(str_url)" & linefeed & linefeed & "str_date_time = datetime.datetime.now().strftime(\"%Y%m%d_%H%M%S\")" & linefeed & "str_filename = f\"{str_date_time}.png\"" & linefeed & "capture_file_path = os.path.join(capture_dir_path,str_filename)" & linefeed & "driver.save_screenshot(capture_file_path)" & linefeed & linefeed & "driver.quit()" & linefeed & "subprocess.run([\"open\", capture_dir_path])" & linefeed & linefeed & "") as text
160
161if boolMoby is true then
162   
163   set strPy to ("#!/usr/bin/env python3" & linefeed & "#coding: utf-8" & linefeed & "import os" & linefeed & "import subprocess" & linefeed & "import time" & linefeed & "import datetime" & linefeed & "from selenium import webdriver" & linefeed & "from selenium.webdriver.edge.service import Service" & linefeed & "from selenium.webdriver.edge.options import Options" & linefeed & "from selenium.webdriver.common.by import By" & linefeed & "from selenium.webdriver.support.ui import WebDriverWait" & linefeed & "from selenium.webdriver.support import expected_conditions as EC" & linefeed & "" & linefeed & "# パス設定" & linefeed & "driver_path = os.path.expanduser(\"" & ocidBinFilePath & "\")" & linefeed & "edge_bin_path = os.path.expanduser(\"" & ocidAppBinPath & "\")" & linefeed & "tmp_dir_path = os.environ[\"TMPDIR\"]" & linefeed & "user_data_path = os.path.join(tmp_dir_path, \"Microsoft Edge Driver\")" & linefeed & "if not os.path.exists(user_data_path):" & linefeed & "  os.makedirs(user_data_path, exist_ok=True)" & linefeed & "os.chdir(user_data_path)" & linefeed & "" & linefeed & "capture_dir_path = os.path.expanduser(\"~/Pictures/ScreenCapture/ScreenCapture\")" & linefeed & "if not os.path.exists(capture_dir_path):" & linefeed & "  os.makedirs(capture_dir_path, exist_ok=True)" & linefeed & "" & linefeed & "options = Options()" & linefeed & "options.add_argument(f\"--user-data-dir={user_data_path}\")" & linefeed & "options.binary_location = edge_bin_path" & linefeed & "" & linefeed & "options.add_argument(\"--headless=new\")" & linefeed & "options.add_argument(\"--disable-gpu\")" & linefeed & "#  options.add_argument(\"--window-size=1920,1080\")" & linefeed & "options.add_argument(\"--window-size=390,1080\")" & linefeed & "" & linefeed & "str_user_agent_mobile = (" & linefeed & "    \"Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) \"" & linefeed & "    \"AppleWebKit/605.1.15 (KHTML, like Gecko) \"" & linefeed & "    \"Version/17.0 Mobile/15E148 Safari/604.1\"" & linefeed & ")" & linefeed & "options.add_argument(f\"--user-agent={str_user_agent_mobile}\")" & linefeed & "" & linefeed & "" & linefeed & "service = Service(executable_path=driver_path)" & linefeed & "app_driver = webdriver.Edge(service=service, options=options)" & linefeed & "" & linefeed & "dict_mobile_metrics = {" & linefeed & "    \"width\": 390," & linefeed & "    \"height\": 1080," & linefeed & "    \"deviceScaleFactor\": 3," & linefeed & "    \"mobile\": True" & linefeed & "}" & linefeed & "" & linefeed & "app_wait = WebDriverWait(app_driver, 15)" & linefeed & "app_driver.get(\"https://note.com/\")" & linefeed & "app_wait.until(EC.presence_of_element_located((By.TAG_NAME, \"a\")))" & linefeed & "time.sleep(5)" & linefeed & "" & linefeed & "print(f\"アクセス完了: {app_driver.title}\")" & linefeed & "" & linefeed & "list_elements = app_driver.find_elements(By.TAG_NAME, \"a\")" & linefeed & "for item_element in list_elements:" & linefeed & "  str_url = item_element.get_attribute(\"href\")" & linefeed & "  str_link_text = item_element.text.strip()" & linefeed & "  if str_link_text:" & linefeed & "    print(str_link_text)" & linefeed & "    print(str_url)" & linefeed & "" & linefeed & "str_date_time = datetime.datetime.now().strftime(\"%Y%m%d_%H%M%S\")" & linefeed & "str_filename = f\"{str_date_time}.png\"" & linefeed & "capture_file_path = os.path.join(capture_dir_path,str_filename)" & linefeed & "app_driver.save_screenshot(capture_file_path)" & linefeed & "" & linefeed & "app_driver.quit()" & linefeed & "subprocess.run([\"open\", capture_dir_path])" & linefeed & "" & linefeed & "") as text
164   
165end if
166
167########################
168#マルチリンガル
169set strBundleID to ("com.apple.finder") as text
170set appBundle to refMe's NSBundle's bundleWithIdentifier:(strBundleID)
171if appBundle = (missing value) then
172   set strAppPath to ("/System/Library/CoreServices/Finder.app") as text
173   set ocidAppPathStr to refMe's NSString's stringWithString:(strAppPath)
174   set ocidAppPath to ocidAppPathStr's stringByStandardizingPath()
175   set ocidAppPathURL to refMe's NSURL's fileURLWithPath:(ocidAppPath) isDirectory:(false)
176   set appBundle to refMe's NSBundle's bundleWithURL:(ocidAppPathURL)
177end if
178set ocidCancel to appBundle's localizedStringForKey:("AL1") value:("Cancel") table:("LocalizableMerged")
179set ocidOK to appBundle's localizedStringForKey:("AL4") value:("OK") table:("LocalizableMerged")
180set ocidAddText to appBundle's localizedStringForKey:("BR3") value:("Add Text") table:("LocalizableMerged")
181set ocidClipboard to appBundle's localizedStringForKey:("CW10") value:("Clipboard") table:("LocalizableMerged")
182set ocidCopy to appBundle's localizedStringForKey:("ME2") value:("Copy") table:("LocalizableMerged")
183set ocidText to appBundle's localizedStringForKey:("GROUP_TEXT") value:("Text") table:("LocalizableMerged")
184set ocidQuit to appBundle's localizedStringForKey:("BN39") value:("Quit Without Saving") table:("LocalizableMerged")
185set ocidClose to appBundle's localizedStringForKey:("FR26") value:("Close") table:("LocalizableMerged")
186set ocidFinish to appBundle's localizedStringForKey:("FR27") value:("Done") table:("LocalizableMerged")
187set ocidSave to appBundle's localizedStringForKey:("AL2") value:("Save") table:("LocalizableMerged")
188set ocidExists to appBundle's localizedStringForKey:("NE73") value:("An item with the same name already exists in this location.") table:("LocalizableMerged")
189set ocidExtensionName to appBundle's localizedStringForKey:("RV_FILE_EXTENSION_SLICE_NAME") value:("File extension slice name") table:("LocalizableMerged")
190########################
191#マルチリンガル
192set strBundleID to ("com.apple.osax.standardadditions") as text
193set appBundle to refMe's NSBundle's bundleWithIdentifier:(strBundleID)
194if appBundle = (missing value) then
195   set strAppPath to ("/System/Library/ScriptingAdditions/StandardAdditions.osax") as text
196   set ocidAppPathStr to refMe's NSString's stringWithString:(strAppPath)
197   set ocidAppPath to ocidAppPathStr's stringByStandardizingPath()
198   set ocidAppPathURL to refMe's NSURL's fileURLWithPath:(ocidAppPath) isDirectory:(false)
199   set appBundle to refMe's NSBundle's bundleWithURL:(ocidAppPathURL)
200end if
201set ocidChoose to appBundle's localizedStringForKey:("Choose") value:("Choose") table:("Localizable")
202set ocidOK to appBundle's localizedStringForKey:("OK") value:("OK") table:("Localizable")
203set ocidOpen to appBundle's localizedStringForKey:("Open") value:("Open") table:("Localizable")
204set ocidCancel to appBundle's localizedStringForKey:("Cancel") value:("Cancel") table:("Localizable")
205set ocidChooseFile to appBundle's localizedStringForKey:("Choose a File") value:("Choose a File") table:("Localizable")
206set ocidChooseFileName to appBundle's localizedStringForKey:("Choose File Name") value:("Choose File Name") table:("Localizable")
207set ocidChooseFolder to appBundle's localizedStringForKey:("Choose a Folder") value:("Choose a Folder") table:("Localizable")
208set ocidSaveAs to appBundle's localizedStringForKey:("Save As") value:("Save As") table:("Localizable")
209set ocidNameAndLocation to appBundle's localizedStringForKey:("Specify new file name and location") value:("Specify new file name and location") table:("Localizable")
210########################
211# ダイアログ
212set strTitle to ("入力してください か 戻り値") as text
213set strMsg to ("動作テスト用のpyファイルです") as text
214set strDefaultAnswer to (strPy) as text
215set strSaveAs to (ocidSaveAs) as text
216set strCopy to ("" & ocidCopy & ocidClipboard & "") as text
217set strQuit to (ocidQuit) as text
218set strOK to (ocidOK) as text
219set strCancel to (ocidCancel) as text
220set listButtons to {strSaveAs, strCopy, strQuit} as list
221set strBundleID to ("com.microsoft.VSCode") as text
222set aliasIconFilePath to doGetIconFilePathURL(strBundleID)'s absoluteURL() as alias
223try
224   tell application "System Events"
225      activate
226      set recordResponse to (display dialog strMsg with title strTitle default answer strDefaultAnswer buttons listButtons default button strCopy cancel button strQuit with icon aliasIconFilePath giving up after 20 without hidden answer) as record
227   end tell
228on error strErrorMes number numErrorNO
229   log strErrorMes & numErrorNO
230   return false
231end try
232set boolGaveUP to (gave up of recordResponse) as boolean
233set strButtonReturned to (button returned of recordResponse) as text
234set strResponse to (text returned of recordResponse) as text
235set ocidResponseString to (refMe's NSString's stringWithString:(strResponse))
236try
237   tell application "System Events" to quit
238end try
239if recordResponse is false then
240   log "キャンセル終了"
241   return false
242else if true is boolGaveUP then
243   log "時間切れですやりなおしてください"
244   return false
245else if strQuit is strButtonReturned then
246   log "キャンセル終了"
247   return false
248else if strCopy is strButtonReturned then
249   ################
250   #ペーストボード
251   set appPasteboard to refMe's NSPasteboard's generalPasteboard()
252   appPasteboard's clearContents()
253   set boolDone to appPasteboard's setString:(ocidResponseString) forType:(refMe's NSPasteboardTypeString)
254   if boolDone is false then
255      tell application "Finder"
256         set the clipboard to strResponse as text
257      end tell
258   end if
259   return true
260else if strSaveAs is strButtonReturned then
261   ################
262   #保存
263   set strSaveFileName to ("edge_selenium_webdriver.py") as text
264   set strTargetExtension to ("py") as text
265   set strMsg to ("" & ocidChooseFileName & return & ocidNameAndLocation & "") as text
266   set strPrompt to ("" & ocidChooseFileName & return & ocidNameAndLocation & "") as text
267   #
268   set appFileManager to refMe's NSFileManager's defaultManager()
269   set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
270   set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
271   set aliasDesktopDirPath to (ocidDesktopDirPathURL's absoluteURL()) as alias
272   try
273      tell application "SystemUIServer"
274         activate
275         set aliaSavesFilePath to (choose file name strMsg with prompt strPrompt default location aliasDesktopDirPath default name strSaveFileName) as «class furl»
276      end tell
277   on error strErrMes number numErrNo
278      log strErrMes & numErrNo
279      return false
280   end try
281   set strSaveFilePath to (POSIX path of aliaSavesFilePath) as text
282   set ocidSaveFilePathStr to refMe's NSString's stringWithString:(strSaveFilePath)
283   set ocidSaveFilePath to ocidSaveFilePathStr's stringByStandardizingPath()
284   set ocidSaveFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidSaveFilePath) isDirectory:false)
285   set ocidContainerDirPathURL to ocidSaveFilePathURL's URLByDeletingLastPathComponent()
286   #拡張子
287   set strExtension to (ocidSaveFilePathURL's pathExtension()) as text
288   #最後のアイテムがファイル名
289   set strFileName to (ocidSaveFilePathURL's lastPathComponent()) as text
290   #拡張子のつけ忘れ対策
291   if strFileName does not contain strTargetExtension then
292      set strFileName to (strFileName & "." & strTargetExtension) as text
293      set ocidSaveFilePathURL to ocidContainerDirPathURL's URLByAppendingPathComponent:(strFileName)
294   end if
295   set ocidEnc to (refMe's NSUTF8StringEncoding)
296   set listDone to ocidResponseString's writeToURL:(ocidSaveFilePathURL) atomically:(true) encoding:(ocidEnc) |error|:(reference)
297   set ocidSaveFilePath to ocidSaveFilePathURL's |path|()
298   set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s init()
299   ocidAttrDict's setObject:(511) forKey:(refMe's NSFilePosixPermissions)
300   set appFileManager to refMe's NSFileManager's defaultManager()
301   set listDone to appFileManager's setAttributes:(ocidAttrDict) ofItemAtPath:(ocidSaveFilePath) |error|:(reference)
302   return true
303else
304   return true
305end if
306return strHTML
307
308########################
309## BundleID 2 IconURL
310to doGetIconFilePathURL(argBundleiD)
311   set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
312   set ocidAppBundle to (refMe's NSBundle's bundleWithIdentifier:(argBundleiD))
313   if ocidAppBundle ≠ (missing value) then
314      set ocidAppPathURL to ocidAppBundle's bundleURL()
315   else if ocidAppBundle = (missing value) then
316      set ocidAppPathURL to (appSharedWorkspace's URLForApplicationWithBundleIdentifier:(argBundleiD))
317   end if
318   log ocidAppPathURL as alias
319   
320   if ocidAppPathURL = (missing value) then
321      tell application "Finder"
322         try
323            set aliasAppApth to (application file id argBundleiD) as alias
324         on error strErrMsg number numErrNo
325            set strAppPath to ("/System/Library/CoreServices/Finder.app") as text
326            set aliasAppApth to (POSIX file strAppPath) as alias
327         end try
328      end tell
329      set strAppPath to (POSIX path of aliasAppApth) as text
330      set strAppPathStr to refMe's NSString's stringWithString:(strAppPath)
331      set strAppPath to strAppPathStr's stringByStandardizingPath()
332      set ocidAppPathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:true
333   end if
334   set appBundle to refMe's NSBundle's bundleWithURL:(ocidAppPathURL)
335   set ocidInfoDict to appBundle's infoDictionary()
336   #   set ocidIconName to ocidInfoDict's objectForKey:("CFBundleIconName")
337   set ocidIconName to ocidInfoDict's objectForKey:("CFBundleIconFile")
338   if ocidIconName ≠ (missing value) then
339      set boolSuffix to ocidIconName's hasSuffix:("icns")
340      if boolSuffix is false then
341         set ocidIconName to ocidIconName's stringByAppendingString:(".icns")
342      end if
343   else
344      set strAppPath to ("/System/Library/CoreServices/Finder.app") as text
345      set ocidAppPathStr to refMe's NSString's stringWithString:(strAppPath)
346      set ocidAppPath to ocidAppPathStr's stringByStandardizingPath()
347      set ocidAppPathURL to refMe's NSURL's fileURLWithPath:(ocidAppPath) isDirectory:(false)
348   end if
349   
350   log ocidAppPathURL as alias
351   #
352   set strIconSubPath to ("Contents/Resources/" & ocidIconName & "") as text
353   set ocidIconFilePathURL to ocidAppPathURL's URLByAppendingPathComponent:(strIconSubPath) isDirectory:(false)
354   set ocidIconFilePath to ocidIconFilePathURL's |path|()
355   set appFileManager to refMe's NSFileManager's defaultManager()
356   set boolDirExists to appFileManager's fileExistsAtPath:(ocidIconFilePath) isDirectory:(false)
357   if boolDirExists is true then
358      return ocidIconFilePathURL
359   else if boolDirExists is false then
360      set strIconFilePath to ("/System/Library/CoreServices/Finder.app/Contents/Resources/Finder.icns") as text
361      set ocidIconFilePathStr to refMe's NSString's stringWithString:(strIconFilePath)
362      set ocidIconFilePath to ocidIconFilePathStr's stringByStandardizingPath()
363      set ocidIconFilePathURL to refMe's NSURL's fileURLWithPath:(ocidIconFilePath) isDirectory:(false)
364      return ocidIconFilePathURL
365   end if
366end doGetIconFilePathURL
367
368
369
370
371
372
AppleScriptで生成しました