| 001 | #!/usr/bin/env osascript |
| 002 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
| 003 | (* |
| 004 | web ドライバーのバージョンを揃える |
| 005 |
|
| 006 | インストール先は |
| 007 | /Users/ユーザーID/Library/Application Support/bin/edgedriver_mac64_m1 |
| 008 |
|
| 009 | https://github.com/MicrosoftEdge/EdgeWebDriver |
| 010 |
|
| 011 | v1 初回作成 |
| 012 | v1.1 インテル対応 |
| 013 |
|
| 014 | com.cocolog-nifty.quicktimer.icefloe *) |
| 015 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
| 016 | use AppleScript version "2.8" |
| 017 | use framework "Foundation" |
| 018 | use framework "UniformTypeIdentifiers" |
| 019 | use framework "AppKit" |
| 020 | use scripting additions |
| 021 | property refMe : a reference to current application |
| 022 |
|
| 023 | ###################### |
| 024 | #設定項目 |
| 025 | #モバイル端末偽装なら true |
| 026 | #通常PC画面サイズなら false |
| 027 | set boolMoby to true as boolean |
| 028 |
|
| 029 |
|
| 030 | ###################### |
| 031 | #バンドルID |
| 032 | set strBundleID to ("com.microsoft.edgemac") as text |
| 033 | #NSBUNDLE |
| 034 | set ocidAppBundle to (refMe's NSBundle's bundleWithIdentifier:(strBundleID)) |
| 035 | if ocidAppBundle ≠ (missing value) then |
| 036 | set ocidAppPathURL to ocidAppBundle's bundleURL() |
| 037 | else if ocidAppBundle = (missing value) then |
| 038 | #NSWorkspace |
| 039 | set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace() |
| 040 | set ocidAppPathURL to (appSharedWorkspace's URLForApplicationWithBundleIdentifier:(strBundleID)) |
| 041 | end if |
| 042 | #ここでアプリケーションが見つからなければ選択する |
| 043 | if 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) |
| 066 | end if |
| 067 | # |
| 068 | set ocidAppBinPathURL to ocidAppPathURL's URLByAppendingPathComponent:("Contents/MacOS/Microsoft Edge") isDirectory:(false) |
| 069 | set ocidAppBinPath to ocidAppBinPathURL's |path|() |
| 070 | # |
| 071 | set 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") |
| 074 | set ocidAppVersion to ocidAppBundle's objectForInfoDictionaryKey:("CFBundleVersion") |
| 075 |
|
| 076 |
|
| 077 |
|
| 078 | ####################################################### |
| 079 | set recordSystemInfo to (system info) as record |
| 080 | set strArt to (CPU type of recordSystemInfo) as text |
| 081 | #バイナリー保存先 |
| 082 | set appFileManager to refMe's NSFileManager's defaultManager() |
| 083 | set ocidForDir to (refMe's NSApplicationSupportDirectory) |
| 084 | set ocidInDomain to (refMe's NSUserDomainMask) |
| 085 | set ocidURLsArray to (appFileManager's URLsForDirectory:(ocidForDir) inDomains:(ocidInDomain)) |
| 086 | set ocidAppSupportDirPathURL to ocidURLsArray's firstObject() |
| 087 | # |
| 088 | if strArt contains "ARM" then |
| 089 | set ocidBinDirPathURL to ocidAppSupportDirPathURL's URLByAppendingPathComponent:("bin/edgedriver_mac64_m1") isDirectory:(true) |
| 090 | else |
| 091 | set ocidBinDirPathURL to ocidAppSupportDirPathURL's URLByAppendingPathComponent:("bin/edgedriver_mac64") isDirectory:(true) |
| 092 | end if |
| 093 | set appFileManager to refMe's NSFileManager's defaultManager() |
| 094 | set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s init() |
| 095 | ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions) |
| 096 | set listDone to appFileManager's createDirectoryAtURL:(ocidBinDirPathURL) withIntermediateDirectories:(true) attributes:(ocidAttrDict) |error|:(reference) |
| 097 | #バイナリー |
| 098 | set ocidBinFilePathURL to ocidBinDirPathURL's URLByAppendingPathComponent:("msedgedriver") isDirectory:(true) |
| 099 | #有無確認 |
| 100 | set ocidBinFilePath to ocidBinFilePathURL's |path|() |
| 101 | set boolDirExists to appFileManager's fileExistsAtPath:(ocidBinFilePath) isDirectory:(true) |
| 102 | if 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 |
| 110 | else |
| 111 | set boolVersion to false |
| 112 | end if |
| 113 |
|
| 114 | if 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 | |
| 155 | end if |
| 156 |
|
| 157 |
|
| 158 |
|
| 159 | 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 & 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 |
|
| 161 | if 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 | |
| 165 | end if |
| 166 |
|
| 167 | ######################## |
| 168 | #マルチリンガル |
| 169 | set strBundleID to ("com.apple.finder") as text |
| 170 | set appBundle to refMe's NSBundle's bundleWithIdentifier:(strBundleID) |
| 171 | if 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) |
| 177 | end if |
| 178 | set ocidCancel to appBundle's localizedStringForKey:("AL1") value:("Cancel") table:("LocalizableMerged") |
| 179 | set ocidOK to appBundle's localizedStringForKey:("AL4") value:("OK") table:("LocalizableMerged") |
| 180 | set ocidAddText to appBundle's localizedStringForKey:("BR3") value:("Add Text") table:("LocalizableMerged") |
| 181 | set ocidClipboard to appBundle's localizedStringForKey:("CW10") value:("Clipboard") table:("LocalizableMerged") |
| 182 | set ocidCopy to appBundle's localizedStringForKey:("ME2") value:("Copy") table:("LocalizableMerged") |
| 183 | set ocidText to appBundle's localizedStringForKey:("GROUP_TEXT") value:("Text") table:("LocalizableMerged") |
| 184 | set ocidQuit to appBundle's localizedStringForKey:("BN39") value:("Quit Without Saving") table:("LocalizableMerged") |
| 185 | set ocidClose to appBundle's localizedStringForKey:("FR26") value:("Close") table:("LocalizableMerged") |
| 186 | set ocidFinish to appBundle's localizedStringForKey:("FR27") value:("Done") table:("LocalizableMerged") |
| 187 | set ocidSave to appBundle's localizedStringForKey:("AL2") value:("Save") table:("LocalizableMerged") |
| 188 | set ocidExists to appBundle's localizedStringForKey:("NE73") value:("An item with the same name already exists in this location.") table:("LocalizableMerged") |
| 189 | set ocidExtensionName to appBundle's localizedStringForKey:("RV_FILE_EXTENSION_SLICE_NAME") value:("File extension slice name") table:("LocalizableMerged") |
| 190 | ######################## |
| 191 | #マルチリンガル |
| 192 | set strBundleID to ("com.apple.osax.standardadditions") as text |
| 193 | set appBundle to refMe's NSBundle's bundleWithIdentifier:(strBundleID) |
| 194 | if 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) |
| 200 | end if |
| 201 | set ocidChoose to appBundle's localizedStringForKey:("Choose") value:("Choose") table:("Localizable") |
| 202 | set ocidOK to appBundle's localizedStringForKey:("OK") value:("OK") table:("Localizable") |
| 203 | set ocidOpen to appBundle's localizedStringForKey:("Open") value:("Open") table:("Localizable") |
| 204 | set ocidCancel to appBundle's localizedStringForKey:("Cancel") value:("Cancel") table:("Localizable") |
| 205 | set ocidChooseFile to appBundle's localizedStringForKey:("Choose a File") value:("Choose a File") table:("Localizable") |
| 206 | set ocidChooseFileName to appBundle's localizedStringForKey:("Choose File Name") value:("Choose File Name") table:("Localizable") |
| 207 | set ocidChooseFolder to appBundle's localizedStringForKey:("Choose a Folder") value:("Choose a Folder") table:("Localizable") |
| 208 | set ocidSaveAs to appBundle's localizedStringForKey:("Save As") value:("Save As") table:("Localizable") |
| 209 | set ocidNameAndLocation to appBundle's localizedStringForKey:("Specify new file name and location") value:("Specify new file name and location") table:("Localizable") |
| 210 | ######################## |
| 211 | # ダイアログ |
| 212 | set strTitle to ("入力してください か 戻り値") as text |
| 213 | set strMsg to ("動作テスト用のpyファイルです") as text |
| 214 | set strDefaultAnswer to (strPy) as text |
| 215 | set strSaveAs to (ocidSaveAs) as text |
| 216 | set strCopy to ("" & ocidCopy & ocidClipboard & "") as text |
| 217 | set strQuit to (ocidQuit) as text |
| 218 | set strOK to (ocidOK) as text |
| 219 | set strCancel to (ocidCancel) as text |
| 220 | set listButtons to {strSaveAs, strCopy, strQuit} as list |
| 221 | set strBundleID to ("com.microsoft.VSCode") as text |
| 222 | set aliasIconFilePath to doGetIconFilePathURL(strBundleID)'s absoluteURL() as alias |
| 223 | try |
| 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 |
| 228 | on error strErrorMes number numErrorNO |
| 229 | log strErrorMes & numErrorNO |
| 230 | return false |
| 231 | end try |
| 232 | set boolGaveUP to (gave up of recordResponse) as boolean |
| 233 | set strButtonReturned to (button returned of recordResponse) as text |
| 234 | set strResponse to (text returned of recordResponse) as text |
| 235 | set ocidResponseString to (refMe's NSString's stringWithString:(strResponse)) |
| 236 | try |
| 237 | tell application "System Events" to quit |
| 238 | end try |
| 239 | if recordResponse is false then |
| 240 | log "キャンセル終了" |
| 241 | return false |
| 242 | else if true is boolGaveUP then |
| 243 | log "時間切れですやりなおしてください" |
| 244 | return false |
| 245 | else if strQuit is strButtonReturned then |
| 246 | log "キャンセル終了" |
| 247 | return false |
| 248 | else 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 |
| 260 | else 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 |
| 303 | else |
| 304 | return true |
| 305 | end if |
| 306 | return strHTML |
| 307 |
|
| 308 | ######################## |
| 309 | ## BundleID 2 IconURL |
| 310 | to 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 |
| 366 | end doGetIconFilePathURL |
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|