AppleScript Safari

[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

|

Googleで検索する


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

#!/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 "Finder"
  set strDefaultAnswer to the clipboard as text
end tell

###ダイアログを前面に出す
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 strSearchText to (text returned of (display dialog "Google検索" default answer strDefaultAnswer)) as text
###検索URL 英語モード
set strBaseURL to "https://www.google.com/search?client=safari&rls=en&ie=UTF-8&oe=UTF-8&q="

#################################
###検索語句を%エンコードする
#################################
set ocidSearchText to refMe's NSMutableString's alloc()'s initWithCapacity:0
ocidSearchText's setString:(strSearchText)
##キャラクタセットを指定
set ocidChrSet to refMe's NSCharacterSet's URLQueryAllowedCharacterSet
set ocidEncodedText to ocidSearchText's stringByAddingPercentEncodingWithAllowedCharacters:(ocidChrSet)
###置換レコード
set recordPercentMap to {|+|:"%2B", |=|:"%3D", |&|:"%26", |$|:"%24"} as record
###ディクショナリにして
set ocidPercentMap to refMe's NSDictionary's alloc()'s initWithDictionary:recordPercentMap
###キーの一覧を取り出します
set ocidAllKeys to ocidPercentMap's allKeys()
###取り出したキー一覧を順番に処理
repeat with itemAllKey in ocidAllKeys
  ##キーの値を取り出して
  set ocidMapValue to (ocidPercentMap's valueForKey:itemAllKey)
  ##置換
  set ocidTextEncodeAS to (ocidEncodedText's stringByReplacingOccurrencesOfString:(itemAllKey) withString:(ocidMapValue))
  ##次の変換に備える
  set ocidEncodedText to ocidTextEncodeAS
end repeat
##検索語句をテキストで確定
set strSearchText to ocidEncodedText as text
###検索語句を付与して
set strSearchURL to (strBaseURL & strSearchText) as text
###Safariで開く
tell application "Safari" to launch
tell application "Safari"
  activate
  ##ウィンドウの数を数えて
  set numCntWindow to (count of every window) as integer
  ###ウィンドウがなければ
  if numCntWindow = 0 then
    ###新規でウィンドウを作る
make new document with properties {name:strSearchText}
    tell front window
      open location strSearchURL
    end tell
  else
    ###ウィンドウがあるなら新規タブで開く
    tell front window
make new tab
      tell current tab
open location strSearchURL
      end tell
    end tell
  end if
end tell


|

[Safari]PDFとして保存

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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
#  com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions


tell application "Safari"
  tell front window
    log bounds as list
  end tell
end tell

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


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
      with timeout of 2 seconds
        set strURL to its URL as text
      end timeout
    end tell
  end tell
end tell

tell application "Finder"
  tell application "System Events"
    key code 102
  end tell
end tell

set strTimeNo to (do shell script "date +\"%Y%m%d%H%M%S\"") as text
##set strFileName to strTimeNo & ".pdf" as text

tell application "Safari"
  activate
  tell application "System Events"
    tell process "Safari"
      set frontmost to true
      tell menu bar 1
        click menu bar item "ファイル"
        delay 1
        tell menu "ファイル"
          click menu item "PDFとして書き出す…"
        end tell
      end tell
      delay 2
      keystroke strTimeNo
      delay 1
      keystroke return
    end tell
  end tell
end tell




|

その他のカテゴリー

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