Safari

[Safari]前面ウィンドウの全てのタブを保存して、後でTABの内容ごと復帰させる(タブグループの名前で保存できるようにした v1.1)



ダウンロード - windowsaveandrestore.zip




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

Windowのタブ保存.applescript
ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003(*
004サファリの前面Windowの内容を保存する
005PLIST形式にして保存しておく tabの構成も保存される
006拡張子は独自のtabgroupを使用
007中身はXML形式のplist
008
009v1 初回作成
010v1.1 ファイル名を選べるようにした
011
012com.cocolog-nifty.quicktimer.icefloe *)
013----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
014use AppleScript version "2.8"
015use framework "Foundation"
016use framework "AppKit"
017use scripting additions
018property refMe : a reference to current application
019
020
021tell application "Safari"
022   set numCntWindow to (count of every window) as integer
023end tell
024
025if numCntWindow = 0 then
026   tell application "Safari"
027      activate
028      display alert "SafariURLを開いていません" buttons {"終了"} default button "終了" cancel button "終了" as informational giving up after 3
029   end tell
030   return "Windowがありません"
031end if
032#保存用のARRAY
033set ocidSaveArray to refMe's NSMutableArray's alloc()'s init()
034
035#アプリケーション
036tell application "Safari"
037   #前面ウィンドウ
038   tell front window
039      set numCurrentTabIndex to (index of current tab) as integer
040      #タブの数を数えて
041      set numCntTab to (count of every tab) as integer
042      #タブの情報を取得
043      repeat with itemNo from 1 to numCntTab by 1
044         tell tab itemNo
045            set numIndex to index as integer
046            set strURL to URL as text
047            set strTitle to name as text
048            set boolVisible to visible as boolean
049         end tell
050         
051         #URL情報をレコードにして
052         if numIndex = numCurrentTabIndex then
053            set recordTAB to {|index|:numIndex, |URL|:strURL, |name|:strTitle, |visible|:boolVisible, |activTab|:true} as record
054         else
055            set recordTAB to {|index|:numIndex, |URL|:strURL, |name|:strTitle, |visible|:boolVisible, |activTab|:false} as record
056         end if
057         
058         set ocidTabDict to refMe's NSMutableDictionary's alloc()'s init()
059         (ocidTabDict's setDictionary:(recordTAB))
060         #リストに追加
061         (ocidSaveArray's addObject:(ocidTabDict))
062      end repeat
063   end tell
064end tell
065
066#PLISTにする
067set ocidFormat to (refMe's NSPropertyListXMLFormat_v1_0)
068set ocidOption to (refMe's NSPropertyListMutableContainersAndLeaves)
069set listResponse to refMe's NSPropertyListSerialization's dataWithPropertyList:(ocidSaveArray) format:(ocidFormat) options:(0) |error|:(reference)
070set ocidPlistData to (item 1 of listResponse)
071
072
073#保存先
074set appFileManager to refMe's NSFileManager's defaultManager()
075set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDocumentDirectory) inDomains:(refMe's NSUserDomainMask))
076set ocidDocumentDirPathURL to ocidURLsArray's firstObject()
077set ocidSaveDirPathURL to ocidDocumentDirPathURL's URLByAppendingPathComponent:("Apple/Safari/SaveWindow") isDirectory:(true)
078set aliasSaveDirPath to (ocidSaveDirPathURL's absoluteURL()) as alias
079
080#フォルダ作成
081set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
082ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
083set listDone to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
084#
085tell application "Safari"
086   tell front window
087      tell current tab
088         set strTabName to name as text
089      end tell
090   end tell
091end tell
092
093#日付を取得してファイル名に
094set strDateNo to doGetDateNo("yyyyMMdd_HHmmss")
095set strSetSaveName to ("" & strTabName & "@" & strDateNo & ".tabgroup") as text
096#
097set strName to (name of current application) as text
098if strName is "osascript" then
099   tell application "Finder" to activate
100else
101   tell current application to activate
102end if
103set strPromptText to "名前を決めてください" as text
104set strMesText to "名前を決めてください" as text
105###ファイル名 ダイアログ
106tell application "SystemUIServer"
107   activate
108   set aliasSaveFilePath to (choose file name strMesText default location aliasSaveDirPath default name strSetSaveName with prompt strPromptText) as «class furl»
109end tell
110tell application "SystemUIServer" to quit
111###パス
112set strSaveFilePath to (POSIX path of aliasSaveFilePath) as text
113set ocidSaveFilePathStr to refMe's NSString's stringWithString:(strSaveFilePath)
114set ocidSaveFilePath to ocidSaveFilePathStr's stringByStandardizingPath()
115set ocidSaveFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidSaveFilePath) isDirectory:false)
116set ocidContainerDirPathURL to ocidSaveFilePathURL's URLByDeletingLastPathComponent()
117###拡張子
118set strExtension to (ocidSaveFilePathURL's pathExtension()) as text
119###最後のアイテムがファイル名
120set strFileName to (ocidSaveFilePathURL's lastPathComponent()) as text
121###拡張子のつけ忘れ対策
122if strFileName does not contain "tabgroup" then
123   set strFileName to (strFileName & ".tabgroup") as text
124   set ocidSaveFilePathURL to ocidContainerDirPathURL's URLByAppendingPathComponent:(strFileName)
125end if
126
127
128#保存 
129set ocidOption to (refMe's NSDataWritingAtomic)
130set listDone to ocidPlistData's writeToURL:(ocidSaveFilePathURL) options:(ocidOption) |error|:(reference)
131
132
133
134##############################
135### 今の日付日間 テキスト
136##############################
137to doGetDateNo(argDateFormat)
138   ####日付情報の取得
139   set ocidDate to current application's NSDate's |date|()
140   ###日付のフォーマットを定義
141   set ocidNSDateFormatter to current application's NSDateFormatter's alloc()'s init()
142   ocidNSDateFormatter's setLocale:(current application's NSLocale's localeWithLocaleIdentifier:"ja_JP_POSIX")
143   set ocidTimeZone to refMe's NSTimeZone's alloc()'s initWithName:"Asia/Tokyo"
144   ocidNSDateFormatter's setTimeZone:(ocidTimeZone)
145   ocidNSDateFormatter's setDateFormat:(argDateFormat)
146   set ocidDateAndTime to ocidNSDateFormatter's stringFromDate:ocidDate
147   set strDateAndTime to ocidDateAndTime as text
148   return strDateAndTime
149end doGetDateNo
AppleScriptで生成しました

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

Windowのタブ復帰.applescript
ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003(*
004サファリの保存したWindowの内容をレストアする
005前面tabも復帰させるようにした
006
007
008v1 初回作成
009v1.1 タブが1つの登録時にエラーにならないようにした
010
011com.cocolog-nifty.quicktimer.icefloe *)
012----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
013use AppleScript version "2.8"
014use framework "Foundation"
015use framework "AppKit"
016use scripting additions
017property refMe : a reference to current application
018
019
020#保存先
021set appFileManager to refMe's NSFileManager's defaultManager()
022#書類フォルダ
023set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDocumentDirectory) inDomains:(refMe's NSUserDomainMask))
024set ocidDocumentDirPathURL to ocidURLsArray's firstObject()
025#保存先ディレクトリ
026set ocidSaveDirPathURL to ocidDocumentDirPathURL's URLByAppendingPathComponent:("Apple/Safari/SaveWindow") isDirectory:(true)
027set aliasSaveDirPath to (ocidSaveDirPathURL's absoluteURL()) as alias
028#コンテンツの収集
029set ocidOption to (refMe's NSDirectoryEnumerationSkipsHiddenFiles)
030set ocidKeyArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
031ocidKeyArray's addObject:(refMe's NSURLPathKey)
032set listResponse to (appFileManager's contentsOfDirectoryAtURL:(ocidSaveDirPathURL) includingPropertiesForKeys:(ocidKeyArray) options:(ocidOption) |error|:(reference))
033set ocidSubPathURLArray to (item 1 of listResponse)
034#ファイル名のリストにする
035set listChooser to {} as list
036repeat with itemURL in ocidSubPathURLArray
037   set strFileName to itemURL's lastPathComponent() as text
038   set end of listChooser to strFileName
039end repeat
040#ダイアログ
041set strName to (name of current application) as text
042if strName is "osascript" then
043   tell application "Finder" to activate
044else
045   tell current application to activate
046end if
047set strTitle to ("選んでください") as text
048set strPrompt to ("選んだ項目で戻します") as text
049try
050   set objResponse to (choose from list listChooser with title strTitle with prompt strPrompt default items (item 1 of listChooser) OK button name "OK" cancel button name "キャンセル" with empty selection allowed without multiple selections allowed)
051on error
052   log "エラーしました"
053   return "エラーしました"
054end try
055log class of objResponse
056if (class of objResponse) is boolean then
057   return "キャンセルしましたA"
058else if (class of objResponse) is list then
059   if objResponse is {} then
060      return "キャンセルしましたB"
061   else
062      set strResponse to (item 1 of objResponse) as text
063   end if
064end if
065#選んだファイルのURL
066set ocidPlistFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strResponse) isDirectory:(false)
067#Plist読み込み NSData's
068set ocidOption to (current application's NSDataReadingMappedIfSafe)
069set listResponse to current application's NSData's alloc()'s initWithContentsOfURL:(ocidPlistFilePathURL) options:(ocidOption) |error|:(reference)
070set ocidPlistData to (item 1 of listResponse)
071#ARRAYにする
072set ocidFormat to (current application's NSPropertyListXMLFormat_v1_0)
073set appPlistSerial to current application's NSPropertyListSerialization
074set ocidOption to current application's NSPropertyListMutableContainersAndLeaves
075set listResponse to appPlistSerial's propertyListWithData:(ocidPlistData) options:(ocidOption) format:(ocidFormat) |error|:(reference)
076#これがPLISTのデータArray形式
077set ocidPlistArray to (item 1 of listResponse)
078#数を数えて
079set numCntArray to ocidPlistArray's |count|()
080#前面TABの記憶用
081set numFrontIndex to (missing value)
082#その数だけ繰り返し
083repeat with itemNo from 0 to (numCntArray - 1) by 1
084   set itemDict to (ocidPlistArray's objectAtIndex:(itemNo))
085   set strSetURL to (itemDict's valueForKey:("URL")) as text
086   #最初だけ新規WINDOW
087   if itemNo = 0 then
088      tell application "Safari"
089         make new document with properties {URL:strSetURL}
090      end tell
091   else
092      #それ以外は新規tab
093      tell application "Safari"
094         tell front window
095            set objTab to make new tab at end of tabs with properties {URL:strSetURL}
096         end tell
097      end tell
098   end if
099   #前面タブの判定
100   set boolFrontMost to (itemDict's valueForKey:("visible")) as boolean
101   if boolFrontMost is true then
102      #前面にするタブを格納
103      set refTab to objTab
104   end if
105end repeat
106tell application "Safari"
107   tell front window
108      set numCntTab to (count of every tab) as integer
109   end tell
110end tell
111if numCntTab > 1 then
112   
113   tell application "Safari"
114      tell front window
115         set current tab to refTab
116      end tell
117   end tell
118end if
AppleScriptで生成しました

| | コメント (0)

[Safari]前面ウィンドウの全てのタブを保存して、後でTABの内容ごと復帰させる(少し改良)



ダウンロード - windowsaveandrestore.zip



Safariの前面Windowsの内容を保存
AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#サファリの前面Windowの内容を保存する
004#PLIST形式にして保存しておく tabの構成も保存される
005#com.cocolog-nifty.quicktimer.icefloe
006----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
007use AppleScript version "2.8"
008use framework "Foundation"
009use framework "AppKit"
010use scripting additions
011property refMe : a reference to current application
012
013
014tell application "Safari"
015  set numCntWindow to (count of every window) as integer
016end tell
017
018if numCntWindow = 0 then
019  tell application "Safari"
020    display alert "SafariでURLを開いていません" buttons {"終了"} default button "終了" cancel button "終了" as informational giving up after 3
021  end tell
022  return "Windowがありません"
023end if
024#保存用のARRAY
025set ocidSaveArray to refMe's NSMutableArray's alloc()'s init()
026
027#アプリケーション
028tell application "Safari"
029  #前面ウィンドウ
030  tell front window
031    #タブの数を数えて
032    set numCntTab to (count of every tab) as integer
033    #タブの情報を取得
034    repeat with itemNo from 1 to numCntTab by 1
035      tell tab itemNo
036        set numIndex to index as integer
037        set strURL to URL as text
038        set strTitle to name as text
039        set boolVisible to visible as boolean
040      end tell
041      #URL情報をレコードにして
042      set recordTAB to {|index|:numIndex, |URL|:strURL, |name|:strTitle, |visible|:boolVisible} as record
043      set ocidTabDict to refMe's NSMutableDictionary's alloc()'s init()
044      (ocidTabDict's setDictionary:(recordTAB))
045      #リストに追加
046      (ocidSaveArray's addObject:(ocidTabDict))
047    end repeat
048  end tell
049end tell
050
051#PLISTにする
052set ocidFormat to (refMe's NSPropertyListXMLFormat_v1_0)
053set ocidOption to (refMe's NSPropertyListMutableContainersAndLeaves)
054set listResponse to refMe's NSPropertyListSerialization's dataWithPropertyList:(ocidSaveArray) format:(ocidFormat) options:(0) |error| :(reference)
055set ocidPlistData to (item 1 of listResponse)
056
057
058#保存先
059set appFileManager to refMe's NSFileManager's defaultManager()
060set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDocumentDirectory) inDomains:(refMe's NSUserDomainMask))
061set ocidDocumentDirPathURL to ocidURLsArray's firstObject()
062set ocidSaveDirPathURL to ocidDocumentDirPathURL's URLByAppendingPathComponent:("Apple/Safari/SaveWindow") isDirectory:(true)
063#フォルダ作成
064set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
065ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
066set listDone to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error| :(reference)
067#日付を取得してファイル名に
068set strDateNo to doGetDateNo("yyyyMMdd_HHmmss")
069set ocidSaveBasePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strDateNo) isDirectory:(false)
070set ocidSaveFilePathURL to ocidSaveBasePathURL's URLByAppendingPathExtension:("tabgroup")
071
072#保存 
073set ocidOption to (refMe's NSDataWritingAtomic)
074set listDone to ocidPlistData's writeToURL:(ocidSaveFilePathURL) options:(ocidOption) |error| :(reference)
075
076
077
078##############################
079### 今の日付日間 テキスト
080##############################
081to doGetDateNo(argDateFormat)
082  ####日付情報の取得
083  set ocidDate to current application's NSDate's |date|()
084  ###日付のフォーマットを定義
085  set ocidNSDateFormatter to current application's NSDateFormatter's alloc()'s init()
086  ocidNSDateFormatter's setLocale:(current application's NSLocale's localeWithLocaleIdentifier:"ja_JP_POSIX")
087  set ocidTimeZone to refMe's NSTimeZone's alloc()'s initWithName:"Asia/Tokyo"
088  ocidNSDateFormatter's setTimeZone:(ocidTimeZone)
089  ocidNSDateFormatter's setDateFormat:(argDateFormat)
090  set ocidDateAndTime to ocidNSDateFormatter's stringFromDate:ocidDate
091  set strDateAndTime to ocidDateAndTime as text
092  return strDateAndTime
093end doGetDateNo
AppleScriptで生成しました

保存したWindowの内容をレストアする
AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#サファリの保存したWindowの内容をレストアする
004#前面tabも復帰させるようにした
005#com.cocolog-nifty.quicktimer.icefloe
006----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
007use AppleScript version "2.8"
008use framework "Foundation"
009use framework "AppKit"
010use scripting additions
011property refMe : a reference to current application
012
013
014#保存先
015set appFileManager to refMe's NSFileManager's defaultManager()
016#書類フォルダ
017set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDocumentDirectory) inDomains:(refMe's NSUserDomainMask))
018set ocidDocumentDirPathURL to ocidURLsArray's firstObject()
019#保存先ディレクトリ
020set ocidSaveDirPathURL to ocidDocumentDirPathURL's URLByAppendingPathComponent:("Apple/Safari/SaveWindow") isDirectory:(true)
021set aliasSaveDirPath to (ocidSaveDirPathURL's absoluteURL()) as alias
022#コンテンツの収集
023set ocidOption to (refMe's NSDirectoryEnumerationSkipsHiddenFiles)
024set ocidKeyArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
025ocidKeyArray's addObject:(refMe's NSURLPathKey)
026set listResponse to (appFileManager's contentsOfDirectoryAtURL:(ocidSaveDirPathURL) includingPropertiesForKeys:(ocidKeyArray) options:(ocidOption) |error| :(reference))
027set ocidSubPathURLArray to (item 1 of listResponse)
028#ファイル名のリストにする
029set listChooser to {} as list
030repeat with itemURL in ocidSubPathURLArray
031  set strFileName to itemURL's lastPathComponent() as text
032  set end of listChooser to strFileName
033end repeat
034#ダイアログ
035set strName to (name of current application) as text
036if strName is "osascript" then
037  tell application "Finder" to activate
038else
039  tell current application to activate
040end if
041set strTitle to ("選んでください") as text
042set strPrompt to ("選んだ項目で戻します") as text
043try
044  set objResponse to (choose from list listChooser with title strTitle with prompt strPrompt default items (item 1 of listChooser) OK button name "OK" cancel button name "キャンセル" with empty selection allowed without multiple selections allowed)
045on error
046  log "エラーしました"
047  return "エラーしました"
048end try
049log class of objResponse
050if (class of objResponse) is boolean then
051  return "キャンセルしましたA"
052else if (class of objResponse) is list then
053  if objResponse is {} then
054    return "キャンセルしましたB"
055  else
056    set strResponse to (item 1 of objResponse) as text
057  end if
058end if
059#選んだファイルのURL
060set ocidPlistFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strResponse) isDirectory:(false)
061#Plist読み込み NSData's
062set ocidOption to (current application's NSDataReadingMappedIfSafe)
063set listResponse to current application's NSData's alloc()'s initWithContentsOfURL:(ocidPlistFilePathURL) options:(ocidOption) |error| :(reference)
064set ocidPlistData to (item 1 of listResponse)
065#ARRAYにする
066set ocidFormat to (current application's NSPropertyListXMLFormat_v1_0)
067set appPlistSerial to current application's NSPropertyListSerialization
068set ocidOption to current application's NSPropertyListMutableContainersAndLeaves
069set listResponse to appPlistSerial's propertyListWithData:(ocidPlistData) options:(ocidOption) format:(ocidFormat) |error| :(reference)
070#これがPLISTのデータArray形式
071set ocidPlistArray to (item 1 of listResponse)
072#数を数えて
073set numCntArray to ocidPlistArray's |count|()
074#前面TABの記憶用
075set numFrontIndex to (missing value)
076#その数だけ繰り返し
077repeat with itemNo from 0 to (numCntArray - 1) by 1
078  set itemDict to (ocidPlistArray's objectAtIndex:(itemNo))
079  set strSetURL to (itemDict's valueForKey:("URL")) as text
080  #最初だけ新規WINDOW
081  if itemNo = 0 then
082    tell application "Safari"
083      make new document with properties {URL:strSetURL}
084    end tell
085  else
086    #それ以外は新規tab
087    tell application "Safari"
088      tell front window
089        set objTab to make new tab at end of tabs with properties {URL:strSetURL}
090      end tell
091    end tell
092  end if
093  #前面タブの判定
094  set boolFrontMost to (itemDict's valueForKey:("visible")) as boolean
095  if boolFrontMost is true then
096    #前面にするタブを格納
097    set refTab to objTab
098  end if
099end repeat
100
101log numFrontIndex
102
103tell application "Safari"
104  tell front window
105    set current tab to refTab
106  end tell
107end tell
108
AppleScriptで生成しました

|

[Safari] javascriptでのURLの取得

aリンク取得
サンプルコード

サンプルソース(参考)
行番号ソース
001var list_GetLinks = [];
002var list_GetElements = document.querySelectorAll("a");
003
004for (var item_Element of list_GetElements) {
005  list_GetLinks.push(item_Element.href);
006}
007var result = list_GetLinks.join(",");
008result;
AppleScriptで生成しました

AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004#com.cocolog-nifty.quicktimer.icefloe
005----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
006use AppleScript version "2.8"
007use scripting additions
008
009
010set strBundleID to "com.apple.Safari" as text
011
012##############
013#ウィンドウチェック
014tell application "Safari"
015  set numCntWindow to (count of every window) as integer
016  if numCntWindow = 0 then
017    return "ウィンドウがありません"
018  end if
019end tell
020
021##############
022#全面のタブのURLを取得して
023tell application "Safari"
024  set numID to id of front window
025  set objTab to current tab of window id numID
026  tell window id numID
027    tell objTab
028      set strURL to URL
029    end tell
030  end tell
031end tell
032
033##############
034#ドメイン名
035set strDelim to AppleScript's text item delimiters
036set AppleScript's text item delimiters to "/"
037set listURL to every text item of strURL
038set AppleScript's text item delimiters to strDelim
039
040set strDomain to (item 3 of listURL) as text
041
042##############
043#JavaScript実行
044tell application "Safari"
045  tell window id numID
046    tell objTab
047      set strResponse to {do JavaScript "var list_GetLinks = [];var list_GetElements = document.querySelectorAll(\"a\");for (var item_Element of list_GetElements) {list_GetLinks.push(item_Element.href);}var result = list_GetLinks.join(\",\"); result;"} as text
048    end tell
049  end tell
050end tell
051#戻り値のテキストをリストに
052set strDelim to AppleScript's text item delimiters
053set AppleScript's text item delimiters to ","
054set listURL to every text item of strResponse
055set AppleScript's text item delimiters to strDelim
056
057##############
058#全リスト
059#リストを順番に処理
060repeat with itemURL in listURL
061  set strURL to itemURL as text
062  log strURL
063end repeat
064
065
066##############
067#内部リンク
068#リストを順番に処理
069repeat with itemURL in listURL
070  set strURL to itemURL as text
071  if strURL contains strDomain then
072    #ここがサイト内リンク
073    log strURL
074  else
075    #ここがサイト外リンク
076    log strURL
077  end if
078end repeat
AppleScriptで生成しました

img src取得
サンプルコード

サンプルソース(参考)
行番号ソース
001var list_GetLinks = [];
002var list_GetElements = document.querySelectorAll("img");
003
004for (var item_Element of list_GetElements) {
005  list_GetLinks.push(item_Element.src);
006}
007var result = list_GetLinks.join(",");
008result;
AppleScriptで生成しました

AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004#com.cocolog-nifty.quicktimer.icefloe
005----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
006use AppleScript version "2.8"
007use scripting additions
008
009
010set strBundleID to "com.apple.Safari" as text
011
012##############
013#ウィンドウチェック
014tell application "Safari"
015  set numCntWindow to (count of every window) as integer
016  if numCntWindow = 0 then
017    return "ウィンドウがありません"
018  end if
019end tell
020
021##############
022#全面のタブのURLを取得して
023tell application "Safari"
024  set numID to id of front window
025  set objTab to current tab of window id numID
026  tell window id numID
027    tell objTab
028      set strURL to URL
029    end tell
030  end tell
031end tell
032
033##############
034#ドメイン名
035set strDelim to AppleScript's text item delimiters
036set AppleScript's text item delimiters to "/"
037set listURL to every text item of strURL
038set AppleScript's text item delimiters to strDelim
039
040set strDomain to (item 3 of listURL) as text
041
042##############
043#JavaScript実行
044tell application "Safari"
045  tell window id numID
046    tell objTab
047      set strResponse to {do JavaScript "var list_GetLinks = [];var list_GetElements = document.querySelectorAll(\"img\");for (var item_Element of list_GetElements) {list_GetLinks.push(item_Element.src);}var result = list_GetLinks.join(\",\"); result;"} as text
048    end tell
049  end tell
050end tell
051#戻り値のテキストをリストに
052set strDelim to AppleScript's text item delimiters
053set AppleScript's text item delimiters to ","
054set listURL to every text item of strResponse
055set AppleScript's text item delimiters to strDelim
056
057##############
058#全リスト
059#リストを順番に処理
060repeat with itemURL in listURL
061  set strURL to itemURL as text
062  log strURL
063end repeat
064
065
066##############
067#内部リンク
068#リストを順番に処理
069repeat with itemURL in listURL
070  set strURL to itemURL as text
071  if strURL contains strDomain then
072    #ここがサイト内リンク
073    log strURL
074  else
075    #ここがサイト外リンク
076    log strURL
077  end if
078end repeat
AppleScriptで生成しました

|

[macOS15.2] Safari. 18.2 WEBページのHTMLダウンロードが出来なくなる

202412130357361_588x194

セキュリティ上の理由か?わからないが
ダウンロードパネルへURLをペーストして
WEBページのHTMLがダウンロード出来なくなった

ちょっとソースみたい時に使っていたので不便でしょうがない
(デベロッパーツールのHTMLソース表示が、私には見にくいのです)

AppleScriptの対応がポンコツ以下なので
使いたく無いが
Firefoxを復活させた
ダウンロードのウィンドウ(お気に入りや履歴と一緒のウィンドウ)
使える機能が残っているのは
Firefoxだけになってしまった…とほほ

ちなみに
WEBKIT系のOrionブラウザのダウンロードパネルは
URLのペーストに対応していない

|

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

|

その他のカテゴリー

Accessibility Acrobat Acrobat 2020 Acrobat 2024 Acrobat AddOn Acrobat Annotation Acrobat AppleScript Acrobat ARMDC Acrobat AV2 Acrobat BookMark Acrobat Classic Acrobat DC Acrobat Dialog Acrobat Distiller Acrobat Form Acrobat GentechAI Acrobat JS Acrobat JS Word Search Acrobat Maintenance Acrobat Manifest Acrobat Menu Acrobat Merge Acrobat Open Acrobat PDFPage Acrobat Plugin Acrobat Preferences Acrobat Preflight Acrobat Print Acrobat Python Acrobat Reader Acrobat Reader Localized Acrobat Reference Acrobat Registered Products Acrobat SCA Acrobat SCA Updater Acrobat Sequ Acrobat Sign Acrobat Stamps Acrobat URL List Mac Acrobat URL List Windows Acrobat Watermark Acrobat Windows Acrobat Windows Reader Admin Admin Account Admin Apachectl Admin ConfigCode Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Mobileconfig Admin NetWork Admin Permission Admin Pkg Admin Power Management Admin Printer Admin Printer Basic Admin Printer Custompapers Admin SetUp Admin SMB Admin softwareupdate Admin Support Admin System Information Admin TCC Admin Tools Admin Umask Admin Users Admin Volumes Admin XProtect Adobe Adobe AUSST Adobe Bridge Adobe Documents Adobe FDKO Adobe Fonts Adobe Reference Adobe RemoteUpdateManager Adobe Sap Code AppKit Apple AppleScript AppleScript Duplicate AppleScript entire contents AppleScript List AppleScript ObjC AppleScript Osax AppleScript PDF AppleScript Pictures AppleScript record AppleScript Video Applications AppStore Archive Archive Keka Attributes Automator BackUp Barcode Barcode Decode Barcode QR Bash Basic Basic Path Bluetooth BOX Browser Calendar CD/DVD Choose Chrome Chromedriver CIImage CityCode CloudStorage Color Color NSColor Color NSColorList com.apple.LaunchServices.OpenWith Console Contacts CotEditor CURL current application Date&Time delimiters Desktop Desktop Position Device Diff Disk do shell script Dock Dock Launchpad DropBox Droplet eMail Encode % Encode Decode Encode HTML Entity Encode UTF8 Error EXIFData exiftool ffmpeg File File Name Finder Finder Window Firefox Folder FolderAction Font List FontCollections Fonts Fonts Asset_Font Fonts ATS Fonts Emoji Fonts Maintenance Fonts Morisawa Fonts Python Fonts Variable Foxit GIF github Guide HTML Icon Icon Assets.car Illustrator Image Events ImageOptim Input Dictionary iPhone iWork Javascript Jedit Ω Json Label Language Link locationd lsappinfo m3u8 Mail Map Math Media Media AVAsset Media AVconvert Media AVFoundation Media AVURLAsset Media Movie Media Music Memo Messages Microsoft Microsoft Edge Microsoft Excel Microsoft Fonts Microsoft Office Microsoft Office Link Microsoft OneDrive Microsoft Teams Mouse Music Node Notes NSArray NSArray Sort NSAttributedString NSBezierPath NSBitmapImageRep NSBundle NSCFBoolean NSCharacterSet NSData NSDecimalNumber NSDictionary NSError NSEvent NSFileAttributes NSFileManager NSFileManager enumeratorAtURL NSFont NSFontManager NSGraphicsContext NSGraphicsContext Crop NSImage NSIndex NSKeyedArchiver NSKeyedUnarchiver NSLocale NSMetadataItem NSMutableArray NSMutableDictionary NSMutableString NSNotFound NSNumber NSOpenPanel NSPasteboard NSpoint NSPredicate NSRange NSRect NSRegularExpression NSRunningApplication NSScreen NSSet NSSize NSString NSString stringByApplyingTransform NSStringCompareOptions NSTask NSTimeZone NSUbiquitous NSURL NSURL File NSURLBookmark NSURLComponents NSURLResourceKey NSURLSession NSUserDefaults NSUUID NSView NSWorkspace Numbers OAuth PDF PDF Image2PDF PDF MakePDF PDF nUP PDF Pymupdf PDF Pypdf PDFContext PDFDisplayBox PDFImageRep PDFKit PDFKit Annotation PDFKit AnnotationWidget PDFKit DocumentPermissions PDFKit OCR PDFKit Outline PDFKit Start PDFPage PDFPage Rotation PDFView perl Photoshop PlistBuddy pluginkit plutil postalcode PostScript PowerShell prefPane Preview Python Python eyed3 Python pip QuickLook QuickTime ReadMe Regular Expression Reminders ReName Repeat RTF Safari SaveFile ScreenCapture ScreenSaver Script Editor Script Menu SF Symbols character id SF Symbols Entity Shortcuts Shortcuts Events sips Skype Slack Sound Spotlight sqlite StandardAdditions StationSearch Subtitles LRC Subtitles SRT Subtitles VTT Swift swiftDialog System Events System Settings 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 Weather webarchive webp Wifi Windows XML XML EPUB XML HTML XML LSSharedFileList XML LSSharedFileList sfl2 XML LSSharedFileList sfl3 XML objectsForXQuery XML OPML XML Plist XML Plist System Events XML RSS XML savedSearch XML SVG XML TTML XML webloc XML xmllint XML XMP YouTube Zero Padding zoom