AppleScript Shortcuts

[Shortcuts]URLスキーム(URLからショートカットを実行する)

URLからショートカットを実行する
https://support.apple.com/ja-jp/guide/shortcuts-mac/apd624386f42/mac

shortcuts://run-shortcut?name=MakeQRcode&input=text&text=美しい日本語

こちらの記事は
このような内容になります
20240217010926_1412x768

|

com.apple.shortcuts.droplet

ショートカットをDockに追加すると出来る アプリケーション(超便利) 起動時に実行させたり出来るので スクリプトの補完としても優秀♪ Screen-20230710-175831 Screen-20230710-180112

|

[Date]日付テキストをクリップボードに

[Date]日付テキストをクリップボードに
https://quicktimer.cocolog-nifty.com/icefloe/2023/02/post-db8a06.html

Shortcuts版

ダウンロード - date2pasteboard.zip

|

[ショートカット]QRコードの『ファイル』をデコードする

ダウンロード - shortcutsfile.zip




20220924172609_1432x1516x1440

#!/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 objMe : a reference to current application
property objNSString : a reference to objMe's NSString
property objNSDictionary : a reference to objMe's NSDictionary
property objNSJSONSerialization : a reference to objMe's NSJSONSerialization



on run {strFilePath}
#####zxing.org使う場合
###set strCommandText to "/usr/bin/curl -d \"f=file\" --data-binary 'decode=@" & strFilePath & "' 'https://zxing.org/w/decode.jspx?'"
#####コマンドライン整形
set strCommandText to "/usr/bin/curl -X POST -H \"Content-Type: multipart/form-data\" -F \"file=@" & strFilePath & "\" \"http://api.qrserver.com/v1/read-qr-code/\" "
#####コマンド実行 戻り値はJSON
set jsonResponse to (do shell script strCommandText) as text
#####NSDictionary初期化
set ocidNSDictionaryM to objNSDictionary's dictionary()
#####↑このNSDictionaryJSONの値を格納
set ocidJsonResponse to (objNSJSONSerialization's JSONObjectWithData:((objNSString's stringWithString:jsonResponse)'s dataUsingEncoding:(objMe's NSUTF8StringEncoding)) options:0 |error|:(missing value))
#####値を取り出す
set recodeCenters to (ocidJsonResponse's symbol)'s valueForKey:"data"
return (recodeCenters as text)
end run

|

[Shortcuts]デスクトップアイコンの表示(MacOS専用)

ダウンロード - e38386e38299e382b9e382afe38388e38383e38395e3829ae382a2e382a4e382b3e383b3e381aee8a1a8e7a4ba.shortcut.zip

20220730-93812

#!/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


set strPlistFileName to "com.apple.finder.plist" as text

####preferences folderまでのパス
tell application "Finder"
set aliasPreferencesDir to (path to preferences folder from user domain) as alias
set strPreferencesDir to POSIX path of aliasPreferencesDir as text
end tell
####ファイル名と繋げてパスにする
set strPlistPath to (strPreferencesDir & strPlistFileName) as text
####まずは今の設定を読み込む
try
tell application "System Events"
tell property list file strPlistPath
set boolCreateDesktop to value of (property list item "CreateDesktop")
end tell
end tell
on error
tell application "System Events"
tell property list file strPlistPath

make new property list item with properties {name:"CreateDesktop", value:true}
set value of property list item "CreateDesktop" to true
end tell
end tell
end try

###今の設定内容と逆のことを実行する
if boolCreateDesktop is true then
display dialog "デスクトップのアイコンを隠します" buttons "OK" default button 1
tell application "System Events"
tell property list file strPlistPath
set value of property list item "CreateDesktop" to false
end tell
end tell

else
display dialog "デスクトップのアイコンを表示します" buttons "OK" default button 1
tell application "System Events"
tell property list file strPlistPath
set value of property list item "CreateDesktop" to true
end tell
end tell
end if


####Finder 再起動
try
tell application "Finder" to quit
end try
delay 2
launch application "Finder"
tell application "Finder" to activate

|

[Shortcuts] Shortcutsを呼び出す

Shortcutsを呼び出す
フォーカスモード(集中モード)は現時点では
コマンド等から変更ができない(やり方知らないだけだけど)ので
あらかじめショートカットでモードのON OFFを作っておく必要があります

20220324144504_1280x674


ダウンロード - e38395e382a9e383bce382abe382b9e383a2e383bce38388e38299.scpt.zip



#!/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 objMe : a reference to current application
property objNSString : a reference to objMe's NSString


set strChkFolderName to "com.cocolog-nifty.force4u"
set aliasAppSupDir to path to application support folder from user domain as alias
tell application "Finder"
set boolFolderExists to exists folder strChkFolderName of folder aliasAppSupDir
if boolFolderExists is false then
make new folder at aliasAppSupDir with properties {name:strChkFolderName}
end if
set label index of folder strChkFolderName of folder aliasAppSupDir to 7
set aliasPrefDir to (folder strChkFolderName of folder aliasAppSupDir) as alias
set strPrefDir to POSIX path of aliasPrefDir as text
end tell
set strPrefFileName to "com.cocolog-nifty.force4u.Shortcuts.plist"
set strPrefFilePath to (strPrefDir & strPrefFileName) as text

try
set strCommandText to ("defaults read \"" & strPrefFilePath & "\" ShortcutsFolderName") as string
set strShortcutsFolderName to (do shell script strCommandText) as text
on error
##plistの基本部分(これを書き込みます)
set strPlistContents to "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"><plist version=\"1.0\"><dict></dict></plist>" as text

tell application "Finder"
set boolFileExists to exists file strPrefFileName of folder aliasPrefDir
if boolFileExists is false then
make new file at aliasPrefDir with properties {name:strPrefFileName, file type:"TEXT", creator type:"ttxt", label index:3}
##中身を書き込む

set objOutPut to objNSString's stringWithString:strPlistContents
objOutPut's writeToFile:strPrefFilePath atomically:false encoding:(objMe's NSUTF8StringEncoding) |error|:(missing value)


set aliasPlistPath to file strPrefFileName of aliasPrefDir as alias
close access (open for access file aliasPlistPath)
write strPlistContents to file aliasPlistPath
end if
end tell

tell application "Shortcuts"
set listShortcutsFolder to (name of every folder) as list
set numShortcutsCnt to (count every folder) as number
end tell

set objResponse to (choose from list listShortcutsFolder with title "フォルダを選んでください" with prompt "リストするフォルダを選んでください" default items (item 1 of listShortcutsFolder) OK button name "OK" cancel button name "キャンセル" with multiple selections allowed without empty selection allowed)

set srtFolderName to objResponse as text

set strCommandText to ("defaults write \"" & strPrefFilePath & "\" ShortcutsFolderName -string \"" & srtFolderName & "\"") as string
do shell script strCommandText
set strShortcutsFolderName to ((objNSString's stringWithString:strShortcutsFolderName)'s stringByApplyingTransform:"Hex-Any" |reverse|:false) as text
end try
#################################################################

set strShortcutsFolderName to strShortcutsFolderName as text


set strShortcutName to ""
set listShortcuts to {}
tell application "Shortcuts"
tell folder strShortcutsFolderName
set numShortcutsCnt to (count every shortcut) as number
end tell
end tell
set numChk to 1
repeat numShortcutsCnt times
tell application "Shortcuts"
tell folder strShortcutsFolderName

set strShortcutName to name of shortcut numChk as text
set strShortcutID to id of shortcut numChk
set strShortcutFolder to folder of shortcut numChk
set strShortcutSubtitle to subtitle of shortcut numChk
end tell
end tell
copy {"" & strShortcutName & ""} to end of listShortcuts

log "ShortcutName " & strShortcutName
log "ShortcutID" & strShortcutID


set numChk to numChk + 1
end repeat


try
set objResponse to (choose from list listShortcuts with title "実行するショートカットを選んでください" with prompt "ショートカット実行" default items (item 1 of listShortcuts) OK button name "OK" cancel button name "キャンセル" with multiple selections allowed without empty selection allowed)
on error
log "エラーしました"
return
end try
if objResponse is false then
return
end if

set strResponse to objResponse as text


tell application "Shortcuts"

tell shortcut strResponse
run
end tell

end tell

set strShortcutName to ""
set listShortcuts to {}

|

[Shortcuts]AppleScriptでフォルダ名を取得する

ショートカット(Shortcuts.app)のフォルダ名を取得

ダウンロード - shortcutse382b5e383b3e38395e3829ae383ab.zip


#!/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 strShortcutName : ""

tell application "Script Editor"

tell application "System Events"
keystroke "l" using {command down, option down}
end tell
end tell
delay 1


tell application "Shortcuts"
set strShortcutName to name of every folder
end tell

|

[Shortcuts]AppleScriptメニューから実行する

ショートカットをスクリプトメニューから実行します

ダウンロード - applescriptshortcuts.zip


#!/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 strShortcutName : ""
property listShortcuts : {}


tell application "Shortcuts"

set numShortcutsCnt to (count every shortcut) as number
end tell
set numChk to 1
repeat numShortcutsCnt times
tell application "Shortcuts"
set strShortcutName to name of shortcut numChk as text
set strShortcutID to id of shortcut numChk
set strShortcutFolder to folder of shortcut numChk
set strShortcutSubtitle to subtitle of shortcut numChk
end tell
copy {"" & strShortcutName & ""} to end of listShortcuts

log "ShortcutName " & strShortcutName
log "ShortcutID" & strShortcutID


set numChk to numChk + 1
end repeat


try
set objResponse to (choose from list listShortcuts with title "実行するショートカットを選んでください" with prompt "ショートカット実行" default items (item 1 of listShortcuts) OK button name "OK" cancel button name "キャンセル" with multiple selections allowed without empty selection allowed)
on error
log "エラーしました"
return
end try
if objResponse is false then
return
end if

set strResponse to objResponse as text


tell application "Shortcuts"

tell shortcut strResponse
run
end tell

end tell

|

[Shortcuts]AppleScriptでショートカットの名前を取得する

1:ショートカットの名前を取得する
2:ショートカットのUUIDを取得する
3:フォルダ名を取得する
4:ショートカットを実行する
5:ショートカットのフォルダ名を取得する

ダウンロード - shortcutse382b5e383b3e38395e3829ae383ab.zip




Shortcutsの名前とIDを取得する

tell application "Script Editor"

tell application "System Events"
keystroke "l" using {command down, option down}
end tell
end tell
delay 1

tell application "Shortcuts"

set numFolderCnt to (count every folder) as number
set numChk to 1
repeat numFolderCnt times
set strFolderName to name of folder numChk
set strFolderID to id of folder numChk
log "フォルダ名:" & strFolderName
log "フォルダID" & strFolderID
set numChk to numChk + 1
end repeat

set numShortcutsCnt to (count every shortcut) as number

set numChk to 1
repeat numShortcutsCnt times
set strShortcutName to name of shortcut numChk
set strShortcutID to id of shortcut numChk
set strShortcutFolder to folder of shortcut numChk
set strShortcutSubtitle to subtitle of shortcut numChk


log "ShortcutName " & strShortcutName
log "ShortcutID" & strShortcutID


set numChk to numChk + 1
end repeat


end tell




Shortcutsフォルダ毎にショートカットを取得
tell application "Script Editor"
tell application "System Events"
keystroke "l" using {command down, option down}
end tell
end tell
delay 1



tell application "Shortcuts"

set numFolderCnt to (count every folder) as number
set numChk to 1
repeat numFolderCnt times
set strFolderName to name of folder numChk
set strFolderID to id of folder numChk
log "フォルダ名:" & strFolderName
log "フォルダID" & strFolderID

tell folder id strFolderID
set numShortcutsCnt to (count shortcut) as number
set numSChk to 1
repeat numShortcutsCnt times
set strShortcutName to name of shortcut numSChk
set strShortcutID to id of shortcut numSChk
set strShortcutFolder to folder of shortcut numSChk
set strShortcutSubtitle to subtitle of shortcut numSChk

log "" & strFolderName & ":ShortcutName " & strShortcutName
log "" & strFolderName & ":ShortcutID" & strShortcutID
log "" & strFolderName & ":ShortcutSubtitle" & strShortcutSubtitle

set numSChk to numSChk + 1
end repeat


end tell
log "---------------------------------------------------"
set numChk to numChk + 1
end repeat



end tell



Shortcuts実行
→これはサンプル実際には自分のショートカット名と置き換える


tell application "Shortcuts"

tell shortcut id "22590EC1-F6E7-47AD-A040-C29169E9EC63"
run
end tell

end tell








tell application "Shortcuts"

tell shortcut "省エネ"
run
end tell

end tell

|

PosixPathをコピー

ダウンロード - PosixPathをコピー.shortcut.zip

Posixpath

|

その他のカテゴリー

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