AppleScript Shortcuts

PDFからテキスト抽出(AppleScrip・ショートカット(Shortcuts)・Automator 詰め合わせ)



ダウンロード - pdf2textcomp.zip



|

[Shortcuts]macOS14.5 スクリーンキャプチャーが利用できない場合の回避方法

ウィンドウの画像で取得する事で回避できる 202405170232362014x516

|

[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

|

その他のカテゴリー

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