Safari

Safariで表示中のページから画像を収集する


AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004(*
005BASE SCRIPT
006https://forum.latenightsw.com/t/list-of-links-on-webpage/1328
007
008WEBページの画像のURLを取得する
009natalieの写真のダウンロードに対応した
010サインインが必要なページは取得できない
011CSS指定の画像は取得できない等
012あまり実用的ではなかった…トホホ
013CURLでHTML取得してファイルを解析した方が良さそう
014*)
015#com.cocolog-nifty.quicktimer.icefloe
016----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
017use AppleScript version "2.8"
018use framework "Foundation"
019use framework "AppKit"
020use scripting additions
021property refMe : a reference to current application
022set appFileManager to refMe's NSFileManager's defaultManager()
023
024
025###全面のタブのURLを取得して
026tell application "Safari"
027  tell front window
028    tell current tab
029      set strURL to URL as text
030    end tell
031  end tell
032end tell
033##############################
034#URL
035set ocidURL to refMe's NSURL's alloc()'s initWithString:(strURL)
036#コンポーネント
037set ocidURLcomp to refMe's NSURLComponents's alloc()'s init()
038ocidURLcomp's setScheme:(ocidURL's |scheme|())
039ocidURLcomp's setHost:(ocidURL's |host|())
040set ocidBaseURL to ocidURLcomp's |URL|()
041#スキーム+ホストのURL
042set ocidBaseURLSTR to refMe's NSMutableString's alloc()'s initWithString:(ocidBaseURL's absoluteString())
043ocidURLcomp's |path|()
044set ocidBaseURL to ocidURLcomp's |URL|()
045#パスまで入れたURL
046set ocidBaseURLPATH to refMe's NSMutableString's alloc()'s initWithString:(ocidBaseURL's absoluteString())
047
048##############################
049#前面ドキュメントのHTMLソース
050tell application "Safari"
051  tell front document
052    set strHTML to source as text
053  end tell
054end tell
055
056##############################
057#戻り値整形
058set ocidResponseText to (refMe's NSString's stringWithString:(strHTML))
059###タブと改行を除去しておく
060set ocidTextM to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
061ocidTextM's appendString:(ocidResponseText)
062###除去する文字列リスト
063set listRemoveChar to {"\n", "\r", "\t"} as list
064##置換
065repeat with itemChar in listRemoveChar
066  set strPattern to itemChar as text
067  set strTemplate to ("") as text
068  set ocidOption to (refMe's NSRegularExpressionCaseInsensitive)
069  set listResponse to (refMe's NSRegularExpression's regularExpressionWithPattern:(strPattern) options:(ocidOption) |error| :(reference))
070  if (item 2 of listResponse) ≠ (missing value) then
071    log (item 2 of listResponse)'s localizedDescription() as text
072    return "正規表現パターンに誤りがあります"
073  else
074    set ocidRegex to (item 1 of listResponse)
075  end if
076  set numLength to ocidResponseText's |length|()
077  set ocidRange to refMe's NSRange's NSMakeRange(0, numLength)
078  set ocidResponseText to (ocidRegex's stringByReplacingMatchesInString:(ocidResponseText) options:0 range:(ocidRange) withTemplate:(strTemplate))
079end repeat
080
081##############################
082#NSADATA
083set ocidHTMLData to ocidResponseText's dataUsingEncoding:(refMe's NSUTF8StringEncoding)
084
085##############################
086#XML
087set ocidOption to (refMe's NSXMLNodePreserveAll) + (refMe's NSXMLDocumentTidyHTML)
088
089set listResponse to refMe's NSXMLDocument's alloc()'s initWithData:(ocidHTMLData) options:(ocidOption) |error| :(reference)
090if (item 2 of listResponse) = (missing value) then
091  log "正常処理"
092  set ocidXMLDoc to (item 1 of listResponse)
093else if (item 2 of listResponse) ≠ (missing value) then
094  log (item 2 of listResponse)'s code() as text
095  log (item 2 of listResponse)'s localizedDescription() as text
096  log "NSXMLDocumentエラー 警告がありました"
097  set ocidXMLDoc to (item 1 of listResponse)
098end if
099
100##############################
101#次工程に渡すARRAY
102set ocidNodeArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
103#タイプA
104set listResponse to (ocidXMLDoc's nodesForXPath:"//*[@src]/attribute::src"  |error| :(reference))
105if (item 2 of listResponse) = (missing value) then
106  log "正常処理"
107  set ocidAttarURLArray to (item 1 of listResponse)
108  ocidNodeArray's addObjectsFromArray:(ocidAttarURLArray)
109else if (item 2 of listResponse) ≠ (missing value) then
110  log (item 2 of listResponse)'s code() as text
111  log (item 2 of listResponse)'s localizedDescription() as text
112  return "エラーしました"
113end if
114#タイプB
115set listResponse to (ocidXMLDoc's nodesForXPath:"//*[@data-src]/attribute::data-src"  |error| :(reference))
116if (item 2 of listResponse) = (missing value) then
117  log "正常処理"
118  set ocidAttarURLArray to (item 1 of listResponse)
119  ocidNodeArray's addObjectsFromArray:(ocidAttarURLArray)
120else if (item 2 of listResponse) ≠ (missing value) then
121  log (item 2 of listResponse)'s code() as text
122  log (item 2 of listResponse)'s localizedDescription() as text
123  return "エラーしました"
124end if
125
126
127##############################
128#####Attar to Array
129##############################
130#次工程用のリスト
131set ocidURLArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
132set ocidURLAllArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
133#次工程用拡張子リスト
134set listExtension to {"jpg", "jpeg", "png", "webp", "gif"} as list
135set ocidExtensionArray to refMe's NSArray's alloc()'s initWithArray:(listExtension)
136#取得したアトリビュートの数だけ繰り返し
137repeat with itemArray in ocidNodeArray
138  #テキストにして
139  set ocidValue to itemArray's stringValue()
140  (ocidURLAllArray's addObject:(ocidValue))
141  set ocidFirstChr to (ocidValue's substringToIndex:(1))
142  set ocidScheme to (ocidValue's substringToIndex:(4))
143  #絶対パスなら
144  if (ocidFirstChr as text) is "/" then
145    (ocidBaseURLSTR's appendString:(ocidValue))
146    set strValue to ocidBaseURLSTR as text
147    #相対パスなら
148  else if (ocidScheme as text) is not "http" then
149    (ocidBaseURLPATH's appendString:(ocidValue))
150    set strValue to ocidBaseURLPATH as text
151  else
152    #URLなら
153    set strValue to ocidValue as text
154  end if
155  #テキストをURLにして
156  set ocidURLString to (refMe's NSString's stringWithString:(strValue))
157  set ocidValueURL to (refMe's NSURL's alloc()'s initWithString:(ocidURLString))
158  if ocidValueURL ≠ (missing value) then
159    #拡張子取得
160    set ocidExtension to ocidValueURL's pathExtension()
161    #対象拡張子リストに含まれるなら
162    set boolContain to (ocidExtensionArray's containsObject:(ocidExtension))
163    if boolContain is true then
164      #クエリーを除去
165      set ocidUrlComponents to (refMe's NSURLComponents's componentsWithURL:(ocidValueURL) resolvingAgainstBaseURL:(false))
166      (ocidUrlComponents's setQuery:(missing value))
167      set ocidImgURL to ocidUrlComponents's |URL|()
168      #次工程リストに追加する
169      (ocidURLArray's addObject:(ocidImgURL))
170    end if
171  end if
172end repeat
173
174##############################
175#####ダウンロード
176##############################
177set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDownloadsDirectory) inDomains:(refMe's NSUserDomainMask))
178set ocidDownloadsDirPathURL to ocidURLsArray's firstObject()
179#フォルダ名はホスト名
180set ocidHostName to ocidURL's |host|()
181set ocidSaveDirPathURL to ocidDownloadsDirPathURL's URLByAppendingPathComponent:(ocidHostName)
182#フォルダアクセス権
183set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
184ocidAttrDict's setValue:(493) forKey:(refMe's NSFilePosixPermissions)
185#フォルダを作る
186set listDone to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error| :(reference)
187if (item 1 of listDone) is true then
188  log "正常処理"
189else if (item 2 of listDone) ≠ (missing value) then
190  log (item 2 of listDone)'s code() as text
191  log (item 2 of listDone)'s localizedDescription() as text
192  return "フォルダ作成エラーしました"
193end if
194set numCntArray to ocidURLArray's |count|()
195##URLを順番に処理
196repeat with itemNo from 0 to (numCntArray - 1) by 1
197  set itemURL to (ocidURLArray's objectAtIndex:(itemNo))
198  set ocidSaveFileName to itemURL's lastPathComponent()
199  set ocidSaveFilePathURL to (ocidSaveDirPathURL's URLByAppendingPathComponent:(ocidSaveFileName))
200  #ダウンロード
201  set ocidOption to (refMe's NSDataReadingMappedIfSafe)
202  set listResponse to (refMe's NSData's alloc()'s initWithContentsOfURL:(itemURL) options:(ocidOption) |error| :(reference))
203  if (item 2 of listResponse) = (missing value) then
204    log "正常処理"
205    set ocidGetData to (item 1 of listResponse)
206  else if (item 2 of listResponse) ≠ (missing value) then
207    log (item 2 of listResponse)'s code() as text
208    log (item 2 of listResponse)'s localizedDescription() as text
209    return "ダウンロードエラーしました"
210  end if
211  #保存
212  set ocidOption to (refMe's NSDataWritingAtomic)
213  set listDone to (ocidGetData's writeToURL:(ocidSaveFilePathURL) options:(ocidOption) |error| :(reference))
214  if (item 1 of listDone) is true then
215    log "正常処理"
216  else if (item 2 of listDone) ≠ (missing value) then
217    log (item 2 of listDone)'s code() as text
218    log (item 2 of listDone)'s localizedDescription() as text
219    return "ファイル保存エラーしました"
220  end if
221end repeat
222
223#保存先を開く
224set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
225set boolDone to appSharedWorkspace's openURL:(ocidSaveDirPathURL)
226if boolDone is true then
227  log "正常処理"
228else if boolDone is false then
229  set strErrorNO to (item 2 of listDone)'s code() as text
230  set strErrorMes to (item 2 of listDone)'s localizedDescription() as text
231  refMe's NSLog("■:" & strErrorNO & strErrorMes)
232  return "エラーしました" & strErrorNO & strErrorMes
233end if
234
235
AppleScriptで生成しました

|

error "Safariでエラーが起きました: You must enable the 'Allow JavaScript from Apple Events' option in Safari's Develop menu to use 'do JavaScript'." number 8

202404270229451744x3762

|

[macOS14.4対応]SafariでのURLを開く


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

#!/usr/bin/env osascript

set strURL to ("https://quicktimer.cocolog-nifty.com/icefloe/") as text

tell application "Safari"
activate
make new document with properties {URL:strURL}
end tell


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

#!/usr/bin/env osascript

set strURL to "https://quicktimer.cocolog-nifty.com/icefloe/"

tell application "Safari"
activate
  #起動を確実にする→といっても最大10秒
  repeat 10 times
    set booleFrontMost to frontmost as boolean
    if booleFrontMost is true then
      exit repeat
    else
delay 1
    end if
  end repeat
  
  ##ウィンドウの数を数えて
  set numCntWindow to (count of every document) as integer
  if numCntWindow = 0 then
make new document
    tell front window
      tell current tab
        set URL to strURL
      end tell
    end tell
  else if numCntWindow = 1 then
    tell front window
      tell current tab
        set strCurrentURL to URL as text
      end tell
    end tell
    if strCurrentURL starts with "favorites" then
      tell front window
        tell current tab
          set URL to strURL
        end tell
      end tell
    else
      tell front window
        set objTab to make new tab at end of tabs with properties {URL:strURL}
        set current tab to objTab
      end tell
    end if
  else
    tell front window
      set objTab to make new tab at end of tabs with properties {URL:strURL}
      set current tab to objTab
    end tell
  end if
end tell


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


tell application "Safari"
activate
make new document
  tell front document
open location "https://www.yahoo.com"
  end tell
end tell



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

#!/usr/bin/env osascript

# WINDOWがあるばあいはこれ
set strURL to ("https://quicktimer.cocolog-nifty.com/icefloe/") as text

tell application "Safari"
activate
  tell front window
    set objTab to make new tab at end of tabs with properties {URL:strURL}
    set current tab to objTab
  end tell
end tell



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

#!/usr/bin/env osascript


set strURL to ("https://quicktimer.cocolog-nifty.com/icefloe/") as text

tell application "Safari"
activate
make new document
  tell front window
    ###最初のタブ
    set objTab to make new tab at front of tabs with properties {URL:strURL}
    set current tab to objTab
  end tell
end tell




tell application "Safari"
activate
make new document
  tell front window
    ##最後のタブ
    set objTab to make new tab at end of tabs with properties {URL:strURL}
    set current tab to objTab
  end tell
end tell


|

[Safari]『Safari』でURLを開く


#!/bin/bash
#com.cocolog-nifty.quicktimer.icefloe
#################################################
STR_URL="https://quicktimer.cocolog-nifty.com/icefloe/"
/usr/bin/open -a Safari "$STR_URL"

exit 0



#!/bin/bash
#com.cocolog-nifty.quicktimer.icefloe
#################################################
STR_URL="x-safari-https://quicktimer.cocolog-nifty.com/icefloe/"
/usr/bin/open "$STR_URL"

exit 0



#!/bin/bash
#com.cocolog-nifty.quicktimer.icefloe
#################################################
STR_URL="https://quicktimer.cocolog-nifty.com/icefloe/"
/usr/bin/open -b com.apple.Safari "$STR_URL"
exit 0


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



set strURL to "x-safari-https://quicktimer.cocolog-nifty.com/icefloe/"
tell application "Finder"
open location strURL
end tell





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


set strURL to "https://quicktimer.cocolog-nifty.com/icefloe/"


tell application "Safari"
activate
  #起動を確実にする→といっても最大10秒
  repeat 10 times
    set booleFrontMost to frontmost as boolean
    if booleFrontMost is true then
      exit repeat
    else
delay 1
    end if
  end repeat
  
  ##ウィンドウの数を数えて
  set numCntWindow to (count of every window) as integer
  if numCntWindow = 0 then
make new document with properties {name:""}
    tell front window
      tell current tab
        set URL to strURL
      end tell
    end tell
  else if numCntWindow = 1 then
    tell front window
      tell current tab
        set strCurrentURL to URL as text
      end tell
    end tell
    if strCurrentURL starts with "favorites" then
      tell front window
        tell current tab
          set URL to strURL
        end tell
      end tell
    else
      tell front window
        set objTab to make new tab at end of tabs with properties {URL:strURL}
        set current tab to objTab
      end tell
    end if
    
  else
    tell front window
      set objTab to make new tab at end of tabs with properties {URL:strURL}
      set current tab to objTab
    end tell
  end if
end tell


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions
property refMe : a reference to current application


set ocidURLComponents to refMe's NSURLComponents's alloc()'s init()
###スキーム を追加
ocidURLComponents's setScheme:("x-safari-https")
###パスを追加(setHostじゃないよ)
ocidURLComponents's setHost:("quicktimer.cocolog-nifty.com")
ocidURLComponents's setPath:("/icefloe/")
##URLに戻して テキストにしておく
set ocidOpenURL to ocidURLComponents's |URL|()
set strOpenURL to ocidOpenURL's absoluteString() as text
log strOpenURL
### OPEN URL
set appShardWorkspace to refMe's NSWorkspace's sharedWorkspace()
set boolDone to appShardWorkspace's openURL:(ocidOpenURL)

|

[Safari]開発メニューを出す(macOS14対応)


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "Appkit"
use scripting additions

property refMe : a reference to current application
set appWorkspace to refMe's NSWorkspace's sharedWorkspace()
set appFileManager to refMe's NSFileManager's defaultManager()

#####設定項目
set listFileName to {"com.apple.Safari.plist", "com.apple.Safari.SandboxBroker.plist"} as list

##bool値
set ocidFalse to (refMe's NSNumber's numberWithBool:false)'s boolValue
set ocidTrue to (refMe's NSNumber's numberWithBool:true)'s boolValue

################
## ファイルパス関連
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidLibraryDirPathURL to ocidURLsArray's firstObject()
set ocidPreferencesURL to ocidLibraryDirPathURL's URLByAppendingPathComponent:("Preferences")
##ファイルの数だけ繰り返し
repeat with itemFileName in listFileName
  ##URLにして
  set ocidPlistFilePathURL to (ocidPreferencesURL's URLByAppendingPathComponent:(itemFileName))
  ################
  ## ファイル読み込み
  set ocidReadPlistData to (refMe's NSMutableDictionary's dictionaryWithContentsOfURL:(ocidPlistFilePathURL) |error|:(reference))
  if (item 1 of ocidReadPlistData) = (missing value) then
    set ocidPlistDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
  else
    set ocidPlistDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
(ocidPlistDict's setDictionary:(item 1 of ocidReadPlistData))
  end if
  ###
  set ocidMinimumWidthsDict to (ocidPlistDict's objectForKey:("PreferencesModulesMinimumWidths"))
  if ocidMinimumWidthsDict = (missing value) then
    set ocidMinimumWidthsDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
(ocidMinimumWidthsDict's setObject:(ocidTrue) forKey:("DeveloperMenuVisibility"))
(ocidPlistDict's setObject:(ocidMinimumWidthsDict) forKey:("PreferencesModulesMinimumWidths"))
  else
(ocidMinimumWidthsDict's setObject:(ocidTrue) forKey:("DeveloperMenuVisibility"))
  end if
  ###
  set ocidValue to (refMe's NSNumber's numberWithInteger:(1))'s integerValue
(ocidPlistDict's setValue:(ocidValue) forKey:("SavePanelFileFormat"))
  ############
  ## Booleanタイプ
(ocidPlistDict's setValue:(ocidTrue) forKey:("IncludeDevelopMenu"))
  #
(ocidPlistDict's setValue:(ocidTrue) forKey:("ShowDevelopMenu"))
  #
(ocidPlistDict's setValue:(ocidTrue) forKey:("DeveloperMenuVisibility"))
  #
(ocidPlistDict's setValue:(ocidTrue) forKey:("WebKitOmitPDFSupport"))
  #
(ocidPlistDict's setValue:(ocidTrue) forKey:("DidMigrateDownloadFolderToSandbox"))
  #
(ocidPlistDict's setValue:(ocidTrue) forKey:("DidMigrateResourcesToSandbox"))
  #
(ocidPlistDict's setValue:(ocidFalse) forKey:("AlwaysPromptForDownloadFolder"))
  ################
  ##書き込み
  set listDone to (ocidPlistDict's writeToURL:(ocidPlistFilePathURL) atomically:(true))
  
end repeat

##コンテナ(Cloundで同期する設定)
set ocidPreferencesURL to ocidLibraryDirPathURL's URLByAppendingPathComponent:("Containers/com.apple.Safari/Data/Library/Preferences")
##ファイルの数だけ繰り返し
repeat with itemFileName in listFileName
  ##ファイルの数だけ繰り返し
  set ocidPlistFilePathURL to (ocidPreferencesURL's URLByAppendingPathComponent:(itemFileName))
  ################
  ## ファイル読み込み
  set ocidReadPlistData to (refMe's NSMutableDictionary's dictionaryWithContentsOfURL:(ocidPlistFilePathURL) |error|:(reference))
  if (item 1 of ocidReadPlistData) = (missing value) then
    set ocidPlistDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
  else
    set ocidPlistDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
(ocidPlistDict's setDictionary:(item 1 of ocidReadPlistData))
  end if
  
  set ocidValue to (refMe's NSNumber's numberWithInteger:(1))'s integerValue
(ocidPlistDict's setValue:(ocidValue) forKey:("SavePanelFileFormat"))
  ############
  ## Booleanタイプ
  set ocidFalse to (refMe's NSNumber's numberWithBool:false)'s boolValue
  set ocidTrue to (refMe's NSNumber's numberWithBool:true)'s boolValue
  #
(ocidPlistDict's setValue:(ocidTrue) forKey:("IncludeDevelopMenu"))
  #
(ocidPlistDict's setValue:(ocidTrue) forKey:("ShowDevelopMenu"))
  #
(ocidPlistDict's setValue:(ocidTrue) forKey:("WebKitOmitPDFSupport"))
  #
(ocidPlistDict's setValue:(ocidTrue) forKey:("DidMigrateDownloadFolderToSandbox"))
  #
(ocidPlistDict's setValue:(ocidTrue) forKey:("DidMigrateResourcesToSandbox"))
  #
(ocidPlistDict's setValue:(ocidFalse) forKey:("AlwaysPromptForDownloadFolder"))
  ################
  ##書き込み
  set listDone to (ocidPlistDict's writeToURL:(ocidPlistFilePathURL) atomically:(true))
  
end repeat




#####CFPreferencesを再起動させて変更後の値をロードさせる
set strCommandText to ("/usr/bin/killall cfprefsd") as text
do shell script strCommandText

return

################
##起動
tell application id strBundleID to quit
delay 3
tell application id strBundleID to activate





|

[screencapture]Safariの画面をキャプチャー


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#com.cocolog-nifty.quicktimer.icefloe
#
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions
property refMe : a reference to current application
## 時間取得
set strDateAndTimt to doGetDateNo({"yyyyMMdd-hhmmss", 1})
## ファイル名定義
set strKeyName to ("ScreenCapture") as text
set strFileName to ("" & strKeyName & "_" & strDateAndTimt & ".png") as text
##保存先
set strSaveDirPath to ("~/Downloads/ScreenCapture/" & strKeyName & "/") as text
set ocidSaveDirPathStr to refMe's NSString's stringWithString:(strSaveDirPath)
set ocidSaveDirPath to ocidSaveDirPathStr's stringByStandardizingPath()
set ocidSaveDirPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidSaveDirPath) isDirectory:true)
##保存先確保
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
# 777-->511 755-->493 700-->448 766-->502
ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
###保存先 ファイルパス
set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strFileName) isDirectory:(false)
set strSaveFilePath to (ocidSaveFilePathURL's |path|()) as text

###サファリのウィンドウの位置を確定
tell application "Safari"
  tell front window
    properties
  end tell
end tell

tell application "Safari"
  tell front window
    set bounds to {0, 25, 1130, 900}
  end tell
end tell


tell application "Safari"
  activate
  tell front window
    properties
  end tell
end tell

##
# set strCommandText to ("/usr/sbin/screencapture \" -R0,100,1130,800 -t png -o -a -r -x -B com.apple.Safari " & strSaveFilePath & "\"") as text
## RECT指定
# set strCommandText to ("/usr/sbin/screencapture \" -x -R0,100,1130,800 " & strSaveFilePath & "\"") as text
##キャプチャー撮って開く
# set strCommandText to ("/usr/sbin/screencapture \" -Bcom.apple.Safari " & strSaveFilePath & "\" ") as text
##
set strCommandText to ("/usr/sbin/screencapture -R0,100,1130,800 -x -t png -o \"" & strSaveFilePath & "\"") as text
do shell script strCommandText
delay 1

tell application "Safari"
  activate
end tell
##ページを送る (これは左矢印キー)
tell application "System Events"
  key code 123
  tell process "Safari"
key code 123
  end tell
end tell



################################
# 日付 doGetDateNo(argDateFormat,argCalendarNO)
# argCalendarNO 1 NSCalendarIdentifierGregorian 西暦
# argCalendarNO 2 NSCalendarIdentifierJapanese 和暦
################################
to doGetDateNo({argDateFormat, argCalendarNO})
  ##渡された値をテキストで確定させて
  set strDateFormat to argDateFormat as text
  set intCalendarNO to argCalendarNO as integer
  ###日付情報の取得
  set ocidDate to current application's NSDate's |date|()
  ###日付のフォーマットを定義(日本語)
  set ocidFormatterJP to current application's NSDateFormatter's alloc()'s init()
  ###和暦 西暦 カレンダー分岐
  if intCalendarNO = 1 then
    set ocidCalendarID to (current application's NSCalendarIdentifierGregorian)
  else if intCalendarNO = 2 then
    set ocidCalendarID to (current application's NSCalendarIdentifierJapanese)
  else
    set ocidCalendarID to (current application's NSCalendarIdentifierISO8601)
  end if
  set ocidCalendarJP to current application's NSCalendar's alloc()'s initWithCalendarIdentifier:(ocidCalendarID)
  set ocidTimezoneJP to current application's NSTimeZone's alloc()'s initWithName:("Asia/Tokyo")
  set ocidLocaleJP to current application's NSLocale's alloc()'s initWithLocaleIdentifier:("ja_JP_POSIX")
  ###設定
ocidFormatterJP's setTimeZone:(ocidTimezoneJP)
ocidFormatterJP's setLocale:(ocidLocaleJP)
ocidFormatterJP's setCalendar:(ocidCalendarJP)
  # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterNoStyle)
  # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterShortStyle)
  # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterMediumStyle)
  # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterLongStyle)
ocidFormatterJP's setDateStyle:(current application's NSDateFormatterFullStyle)
  ###渡された値でフォーマット定義
ocidFormatterJP's setDateFormat:(strDateFormat)
  ###フォーマット適応
  set ocidDateAndTime to ocidFormatterJP's stringFromDate:(ocidDate)
  ###テキストで戻す
  set strDateAndTime to ocidDateAndTime as text
return strDateAndTime
end doGetDateNo

|

CURLsコピーからのダウンロード


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# サファリ用 SafariのデベロッパーツールからのCURLsコピー用
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application

set appFileManager to refMe's NSFileManager's defaultManager()

##############################
###クリックボードの中のURLを取得
##############################
set ocidPasteboard to refMe's NSPasteboard's generalPasteboard()
###クリックボードの中のURLを取得
set ocidPasteboardTypeString to ocidPasteboard's stringForType:(refMe's NSPasteboardTypeString)
##可変テキスト形式で格納
set ocidCurlURL to refMe's NSMutableString's alloc()'s initWithCapacity:0
ocidCurlURL's setString:ocidPasteboardTypeString
##CURLでコピーしているか?を判断
if (ocidCurlURL as text) starts with "curl" then
  log "処理開始"
  ###サブルーチンに値を渡す
  set ocidDoSeparateURLArrayM to doSeparateURL(ocidCurlURL)
else
return "CURLとしてコピーしてください"
end if
###サブルーチンからの戻り値を分割
set strURLwithQuery to (item 1 of ocidDoSeparateURLArrayM)'s absoluteString() as text
set ocidURL to (item 2 of ocidDoSeparateURLArrayM)
##ファイル名
set ocidFileName to ocidURL's lastPathComponent()
set strURL to ocidURL's absoluteString() as text
set strQuery to (item 3 of ocidDoSeparateURLArrayM) as text
set strHeader to (item 4 of ocidDoSeparateURLArrayM) as text

###ファイル保存先
set ocidUserDownloadsPath to (appFileManager's URLsForDirectory:(refMe's NSDownloadsDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDownLoadFolderPath to item 1 of ocidUserDownloadsPath
###ファイル名は同じにする
set ocidFilePathURL to ocidDownLoadFolderPath's URLByAppendingPathComponent:ocidFileName isDirectory:false
###保存先パス
set strFilePath to ocidFilePathURL's |path|() as text
###コマンド整形
set strCommandText to "/usr/bin/curl '" & strURLwithQuery & "' -o '" & strFilePath & "' " & strHeader & "" as text
log strCommandText
###実行
try
  set strResponse to (do shell script strCommandText) as text
on error
  log strResponse
return strResponse
end try


##############################
###CURLコピーの内容を分割 SAFARI用
(*
戻り値のocidDoSeparateURLArrayMは
{クエリー付きURL、URLのみ、クエリーのみ、ヘッダーのみ}
の形式で戻される
*)
##############################
to doSeparateURL(argCurlURL)
  ###戻り値用のリスト
  set ocidDoSeparateURLArrayM to refMe's NSMutableArray's alloc()'s initWithCapacity:0
  ###『'』でリスト化して2番目がURL
  set ocidDelimiters to (refMe's NSCharacterSet)'s characterSetWithCharactersInString:"'"
  set ocidCurlURLArray to argCurlURL's componentsSeparatedByCharactersInSet:ocidDelimiters
  ###URL確定(クエリー入り)
  set ocidURLString to ocidCurlURLArray's objectAtIndex:1
  set ocidURL to refMe's NSURL's URLWithString:(ocidURLString)
ocidDoSeparateURLArrayM's addObject:(ocidURL)
  
  ###URL部分(クエリー無し)
  set ocidURLComponents to refMe's NSURLComponents's componentsWithURL:(ocidURL) resolvingAgainstBaseURL:true
ocidURLComponents's setQueryItems:(missing value)
  set ocidBaseURL to ocidURLComponents's |URL|
ocidDoSeparateURLArrayM's addObject:(ocidBaseURL)
  
  ###クエリー部分
  set ocidQueryName to ocidURL's query()
  #log ocidQueryName as text
  if ocidQueryName is missing value then
ocidDoSeparateURLArrayM's addObject:""
  else
ocidDoSeparateURLArrayM's addObject:(ocidQueryName)
  end if
  
  ###ヘッダー部処理
  ###改行を取る
  set ocidCurlURLLength to argCurlURL's |length|()
  set ocidCurlURLRange to refMe's NSMakeRange(0, ocidCurlURLLength)
  set ocidOption to refMe's NSCaseInsensitiveSearch
argCurlURL's replaceOccurrencesOfString:("\\n") withString:("") options:(ocidOption) range:(ocidCurlURLRange)
  ##置換
  set ocidCurlURLLength to argCurlURL's |length|()
  set ocidCurlURLRange to refMe's NSMakeRange(0, ocidCurlURLLength)
  set ocidOption to refMe's NSCaseInsensitiveSearch
argCurlURL's replaceOccurrencesOfString:("\n") withString:("") options:(ocidOption) range:(ocidCurlURLRange)
  ##置換
  set ocidCurlURLLength to argCurlURL's |length|()
  set ocidCurlURLRange to refMe's NSMakeRange(0, ocidCurlURLLength)
  set ocidOption to refMe's NSCaseInsensitiveSearch
argCurlURL's replaceOccurrencesOfString:("\\") withString:("") options:(ocidOption) range:(ocidCurlURLRange)
  ##スペース区切りでARRAYに
  set ocidDelimiters to refMe's NSCharacterSet's characterSetWithCharactersInString:" "
  set ocidHeaderArray to argCurlURL's componentsSeparatedByCharactersInSet:(ocidDelimiters)
  ##CURL部削除
ocidHeaderArray's removeObjectAtIndex:0
  ###URL部削除
ocidHeaderArray's removeObjectAtIndex:0
  ###残りがヘッダー
  set ocidHeaderText to ocidHeaderArray's componentsJoinedByString:(" ")
  
ocidDoSeparateURLArrayM's addObject:ocidHeaderText
  ###値を戻す
return ocidDoSeparateURLArrayM
  
end doSeparateURL






|

[AppStore]iPhoneアプリのBundleId(バンドルID)を取得する(改良)


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# https://apps.apple.com/us/genre/ios/id36
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "UniformTypeIdentifiers"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application
set strBundleID to "com.apple.Safari" as text
################################
tell application "Safari"
  set numCntWindow to (count of every window) as integer
  if numCntWindow = 0 then
return "ウィンドウがありません"
  end if
end tell

###サファリの最前面のURL
tell application "Safari"
  set numID to id of front window
  set objTab to current tab of window id numID
  tell window id numID
    tell objTab
      set strURL to URL
    end tell
  end tell
end tell
################################
set strURL to strURL as text
set ocidURLString to refMe's NSString's stringWithString:(strURL)
set ocidURL to refMe's NSURL's alloc()'s initWithString:(ocidURLString)
###
set strHostName to ocidURL's |host|() as text
if strHostName is not "apps.apple.com" then
  set strOpenURL to "https://apps.apple.com/us/genre/ios/id36"
  tell application "Safari"
    open location strOpenURL
  end tell
return "ID取得出来ません"
end if
###ラストパス から デベロッパIDを取得する
set strLastPath to (ocidURL's lastPathComponent()) as text
set ocidLastPath to refMe's NSString's stringWithString:(strLastPath)
set ocidID to ocidLastPath's stringByReplacingOccurrencesOfString:("id") withString:("")
set strIDno to ocidID as text

###データ取得用のURLに整形
set strLookupURL to ("https://itunes.apple.com/lookup?id=" & strIDno & "") as text
set ocidLookup to refMe's NSString's stringWithString:(strLookupURL)
set ocidLookupURL to refMe's NSURL's alloc()'s initWithString:(ocidLookup)
log ocidLookupURL's absoluteString() as text
####JSON
set listReadData to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidLookupURL) options:(refMe's NSDataReadingMappedIfSafe) |error|:(reference)
set coidReadData to item 1 of listReadData
###NSJSONSerialization
set listJSONSerialization to (refMe's NSJSONSerialization's JSONObjectWithData:(coidReadData) options:(refMe's NSJSONReadingMutableContainers) |error|:(reference))
set ocidJsonData to item 1 of listJSONSerialization
###
set ocidJsonDict to refMe's NSDictionary's alloc()'s initWithDictionary:(ocidJsonData)
set ocidResultsArray to ocidJsonDict's valueForKey:("results")
set ocidResultsDict to ocidResultsArray's firstObject()
## set listKeys to ocidResultsDict's allKeys()
set listKeys to {"primaryGenreName", "artworkUrl100", "currency", "sellerUrl", "artworkUrl512", "ipadScreenshotUrls", "fileSizeBytes", "genres", "languageCodesISO2A", "artworkUrl60", "supportedDevices", "trackViewUrl", "description", "bundleId", "version", "artistViewUrl", "userRatingCountForCurrentVersion", "isGameCenterEnabled", "appletvScreenshotUrls", "genreIds", "averageUserRatingForCurrentVersion", "releaseDate", "trackId", "wrapperType", "minimumOsVersion", "formattedPrice", "primaryGenreId", "currentVersionReleaseDate", "userRatingCount", "artistId", "trackContentRating", "artistName", "price", "trackCensoredName", "trackName", "kind", "features", "contentAdvisoryRating", "screenshotUrls", "releaseNotes", "isVppDeviceBasedLicensingEnabled", "sellerName", "averageUserRating", "advisories"} as list

repeat with itemKey in listKeys
  log (ocidResultsDict's valueForKey:(itemKey))
end repeat
set strTrackIName to (ocidResultsDict's valueForKey:("trackName")) as text
set strTrackId to (ocidResultsDict's valueForKey:("trackId")) as text
set strBundleID to (ocidResultsDict's valueForKey:("bundleId")) as text
set strVersion to (ocidResultsDict's valueForKey:("version")) as text
set strArtistId to (ocidResultsDict's valueForKey:("artistId")) as text
set strArtistName to (ocidResultsDict's valueForKey:("artistName")) as text

set strDefaultAnser to ("trackName: " & strTrackIName & "\r") as text
set strDefaultAnser to strDefaultAnser & ("trackId: " & strTrackId & "\r") as text
set strDefaultAnser to strDefaultAnser & ("bundleId: " & strBundleID & "\r") as text
set strDefaultAnser to strDefaultAnser & ("version: " & strVersion & "\r") as text
set strDefaultAnser to strDefaultAnser & ("artistId: " & strArtistId & "\r") as text
set strDefaultAnser to strDefaultAnser & ("artistName: " & strArtistName & "\r") as text


###ダイアログを出して
set aliasIconPath to POSIX file "/System/Applications/App Store.app/Contents/Resources/AppIcon.icns" as alias
set theResponse to 2 as number
try
  set recordResult to (display dialog "アプリ情報" with title "詳細情報" default answer strDefaultAnser buttons {"クリップボードにコピー", "キャンセル", "OK"} default button "OK" cancel button "キャンセル" with icon aliasIconPath giving up after 20 without hidden answer)
on error
  log "エラーしました"
return
end try
if true is equal to (gave up of recordResult) then
return "時間切れですやりなおしてください"
end if
if "OK" is equal to (button returned of recordResult) then
  set strResponse to (text returned of recordResult) as text
end if


###クリップボードコピー
if button returned of recordResult is "クリップボードにコピー" then
  set strText to text returned of recordResult as text
  ####ペーストボード宣言
  set appPasteboard to refMe's NSPasteboard's generalPasteboard()
  set ocidText to (refMe's NSString's stringWithString:(strText))
appPasteboard's clearContents()
appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString)
end if


|

[Safari]表示中のWEBページのweblocファイルを作成する(Windows用にURLファイルも同時開催)


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application

#########################
tell application "Safari"
  set numCntWindow to (count of every window) as integer
end tell
###Safariのウィンドウが無いならダイアログを出す
if numCntWindow ≤ 1 then
  ##デフォルトクリップボードから
  set ocidPasteboard to refMe's NSPasteboard's generalPasteboard()
  set ocidPasteboardArray to ocidPasteboard's readObjectsForClasses:({refMe's NSString}) options:(missing value)
  try
    set ocidPasteboardStrings to (ocidPasteboardArray's objectAtIndex:0) as text
  on error
    set ocidPasteboardStrings to "" as text
  end try
  set strDefaultAnswer to ocidPasteboardStrings as text
  ################################
  ######ダイアログ
  ################################
  #####ダイアログを前面に
  tell current application
    set strName to name as text
  end tell
  ####スクリプトメニューから実行したら
  if strName is "osascript" then
    tell application "Finder" to activate
  else
    tell current application to activate
  end if
  set aliasIconPath to (POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/BookmarkIcon.icns") as alias
  try
    set recordResponse to (display dialog "詳しく" with title "入力してください" default answer strDefaultAnswer buttons {"OK", "キャンセル"} default button "OK" cancel button "キャンセル" with icon aliasIconPath giving up after 20 without hidden answer)
  on error
    log "エラーしました"
return "エラーしました"
  end try
  if true is equal to (gave up of recordResponse) then
return "時間切れですやりなおしてください"
  end if
  if "OK" is equal to (button returned of recordResponse) then
    set strResponse to (text returned of recordResponse) as text
  else
    log "キャンセルしました"
return "キャンセルしました"
  end if
  tell application "Safari"
    open location strResponse
    ####タイトル と URLを取得
every document
    set numWindowID to id of front window
    tell window id numWindowID
      set objCurrentTab to current tab
      tell objCurrentTab
set strURL to URL
set strName to name
      end tell
    end tell
  end tell
else
  tell application "Safari"
    ####タイトル と URLを取得
every document
    set numWindowID to id of front window
    tell window id numWindowID
      set objCurrentTab to current tab
      tell objCurrentTab
set strURL to URL
set strName to name
      end tell
    end tell
  end tell
end if
#########################
##URL
set strURL to strURL as text
set ocidURLString to refMe's NSString's stringWithString:(strURL)
set ocidURL to refMe's NSURL's alloc()'s initWithString:(ocidURLString)
set ocidHostName to ocidURL's |host|()
set strURL to ocidURL's absoluteString() as text
##保存先
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDocumentDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDocumentDirURL to ocidURLsArray's firstObject()
set ocidSafariDirPathURL to ocidDocumentDirURL's URLByAppendingPathComponent:("Safari/Webloc/")
set ocidSaveDirPathURL to ocidSafariDirPathURL's URLByAppendingPathComponent:(ocidHostName)
##フォルダ作る
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
# 777-->511 755-->493 700-->448 766-->502
ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
set aliasSaveDirPathURL to (ocidSaveDirPathURL's absoluteURL()) as alias
#########################
##保存ファイル名
try
  ####WEBページのタイトルを10文字で取得
  set strFileName to (text from character 1 to character 30) of strName
on error
  ####10文字以下の場合はホスト名にする
  set strFileName to ocidHostName as text
end try
set strWeblocFileName to (strFileName & ".webloc") as text
set strUrlFileName to (strFileName & ".url") as text
#########################
##保存先パス
set ocidWeblocFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strWeblocFileName)
set ocidUrlFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strUrlFileName)
#########################
##WEBLOC 内容
set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidPlistDict's setValue:(strURL) forKey:("URL")
ocidPlistDict's setValue:(strName) forKey:("title")
set strDateno to doGetDateNo("yyyyMMdd")
ocidPlistDict's setValue:(strDateno) forKey:("version")
ocidPlistDict's setValue:(strDateno) forKey:("productVersion")
##これは自分用
ocidPlistDict's setValue:(strDateno) forKey:("kMDItemFSCreationDate")

#########################
####weblocファイルを作る
set ocidFromat to refMe's NSPropertyListXMLFormat_v1_0
set listPlistEditDataArray to refMe's NSPropertyListSerialization's dataWithPropertyList:(ocidPlistDict) format:(ocidFromat) options:0 |error|:(reference)
set ocidPlistEditData to item 1 of listPlistEditDataArray
set boolWritetoUrlArray to ocidPlistEditData's writeToURL:(ocidWeblocFilePathURL) options:0 |error|:(reference)
(*
tell application "Finder"
make new internet location file to strURL at aliasSaveDirPathURL with properties {name:"" & strName & "", creator type:"MACS", stationery:false, location:strURL}
end tell
*)
#########################
####URLファイルを作る
set strShortCutFileString to ("[InternetShortcut]\r\nURL=" & strURL & "\r\n") as text
set ocidShortCutFileString to refMe's NSMutableString's alloc()'s initWithCapacity:0
ocidShortCutFileString's setString:(strShortCutFileString)
##保存
set boolDone to ocidShortCutFileString's writeToURL:(ocidUrlFilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)

#########################
####保存先を開く
tell application "Finder"
  set aliasSaveFile to (file strWeblocFileName of folder aliasSaveDirPathURL) as alias
  set refNewWindow to make new Finder window
  tell refNewWindow
    set position to {10, 30}
    set bounds to {10, 30, 720, 480}
  end tell
  set target of refNewWindow to aliasSaveDirPathURL
  set selection to aliasSaveFile
end tell

#########################
####バージョンで使う日付
to doGetDateNo(strDateFormat)
  ####日付情報の取得
  set ocidDate to current application's NSDate's |date|()
  ###日付のフォーマットを定義
  set ocidNSDateFormatter to current application's NSDateFormatter's alloc()'s init()
ocidNSDateFormatter's setLocale:(current application's NSLocale's localeWithLocaleIdentifier:"ja_JP_POSIX")
ocidNSDateFormatter's setDateFormat:strDateFormat
  set ocidDateAndTime to ocidNSDateFormatter's stringFromDate:ocidDate
  set strDateAndTime to ocidDateAndTime as text
return strDateAndTime
end doGetDateNo

|

KeyCode3種(デベロッパツールを開く)


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions


tell application id "com.apple.Safari"
  set numCntWin to (count of every window) as integer
end tell

if numCntWin = 0 then
  log "ウィンドがありません"
return "ウィンドがありません"
end if

tell application id "com.apple.Safari"
  activate
  tell application "System Events"
    tell process "Safari"
key code 34 using {command down, option down}
    end tell
  end tell
end tell



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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions


tell application id "com.apple.Safari"
  set numCntWin to (count of every window) as integer
end tell

if numCntWin = 0 then
  log "ウィンドがありません"
return "ウィンドがありません"
end if

tell application id "com.apple.Safari"
  activate
  tell application "System Events"
    tell process "Safari"
key down {command}
key down {option}
      keystroke "i"
key up {option, command}
      
      
    end tell
  end tell
end tell


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions


tell application id "com.apple.Safari"
  set numCntWin to (count of every window) as integer
end tell

if numCntWin = 0 then
  log "ウィンドがありません"
return "ウィンドがありません"
end if

tell application id "com.apple.Safari"
  activate
  tell application "System Events"
    tell process "Safari"
      keystroke "i" using {command down, option down}
    end tell
  end tell
end tell

|

その他のカテゴリー

Accessibility Acrobat Acrobat 2020 Acrobat AddOn Acrobat Annotation Acrobat ARMDC Acrobat AV2 Acrobat BookMark Acrobat Classic Acrobat DC Acrobat Dialog Acrobat Distiller Acrobat Form Acrobat JS Acrobat Manifest Acrobat Menu Acrobat Open Acrobat Plugin Acrobat Preferences Acrobat Preflight Acrobat python Acrobat Reader Acrobat SCA Acrobat SCA Updater Acrobat Sequ Acrobat Sign Acrobat Stamps Acrobat Watermark Acrobat Windows Acrobat Windows Reader Admin Admin Account Admin Apachectl Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Mobileconfig Admin Permission Admin Pkg Admin Power Management Admin Printer Admin SetUp Admin SMB Admin Support Admin System Information Admin Tools Admin Users Admin Volumes Adobe Adobe FDKO Adobe RemoteUpdateManager AppKit Apple AppleScript AppleScript do shell script AppleScript List AppleScript ObjC AppleScript Osax AppleScript PDF AppleScript Pictures AppleScript record AppleScript Script Editor AppleScript Script Menu AppleScript Shortcuts AppleScript Shortcuts Events AppleScript System Events AppleScript System Events Plist AppleScript Video Applications AppStore Archive Attributes Automator BackUp Barcode Barcode QR Barcode QR Decode Bash Basic Basic Path Bluetooth BOX Browser Calendar CD/DVD Choose Chrome CIImage CityCode CloudStorage Color com.apple.LaunchServices.OpenWith Console Contacts CotEditor CURL current application Date&Time delimiters Desktop Device Diff Disk Dock DropBox Droplet eMail Encode % Encode Decode Encode UTF8 Error EXIFData ffmpeg File Finder Firefox Folder FolderAction Fonts GIF github Guide HTML HTML Entity Icon Illustrator Image Events Image2PDF ImageOptim iPhone iWork Javascript Jedit Json Label Leading Zero List locationd LRC lsappinfo LSSharedFileList m3u8 Mail MakePDF Map Math Media Media AVAsset Media AVconvert Media AVFoundation Media AVURLAsset Media Movie Media Music Memo Messages Microsoft Microsoft Edge Microsoft Excel Mouse Music NetWork Notes NSArray NSArray Sort NSBezierPath NSBitmapImageRep NSBundle NSCFBoolean NSCharacterSet NSColor NSColorList NSData NSDecimalNumber NSDictionary NSError NSEvent NSFileAttributes NSFileManager NSFileManager enumeratorAtURL NSFont NSFontManager NSGraphicsContext NSImage NSIndex NSKeyedArchiver NSKeyedUnarchiver NSLocale NSMutableArray NSMutableDictionary NSMutableString NSNotFound NSNumber NSOpenPanel NSPasteboard NSpoint NSPredicate NSPrintOperation NSRange NSRect NSRegularExpression NSRunningApplication NSScreen NSSize NSString NSString stringByApplyingTransform NSStringCompareOptions NSTask NSTimeZone NSURL NSURL File NSURLBookmark NSURLComponents NSURLResourceKey NSURLSession NSUserDefaults NSUUID NSView NSWorkspace Numbers OAuth OneDrive PDF PDFAnnotation PDFAnnotationWidget PDFContext PDFDisplayBox PDFDocumentPermissions PDFImageRep PDFKit PDFnUP PDFOutline perl Photoshop PlistBuddy pluginkit postalcode PostScript prefPane Preview Python QuickLook QuickTime ReadMe Regular Expression Reminders ReName Repeat RTF Safari SaveFile ScreenCapture ScreenSaver SF Symbols character id SF Symbols Entity sips Skype Slack Sound Spotlight sqlite SRT StandardAdditions Swift System Settings TCC TemporaryItems Terminal Text Text CSV Text MD Text TSV TextEdit Tools Translate Trash Twitter Typography UI Unit Conversion UTType valueForKeyPath Video VisionKit Visual Studio Code VMware Fusion Wacom webarchive webp Wifi Windows XML XML EPUB XML OPML XML Plist XML RSS XML savedSearch XML SVG XML TTML XML webloc XML XMP YouTube zoom