AppleScript名:ASOCでスペルチェック |
— Created 2015-12-09 14:52:51 +0900 by Takaaki Naganoya — 2015 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "AppKit" set aStr to current application’s NSString’s stringWithString:"This is a pen." set aChecker to current application’s NSSpellChecker’s sharedSpellChecker() –’s setLanguage:"en_US") –’s checkSpellingOfString:aStr startingAt:0 aChecker’s setLanguage:"English" aChecker’s checkSpellingOfString:aStr startingAt:0 |
カテゴリー: System
システムスペルチェック辞書への学習と削除
AppleScript名:システムスペルチェック辞書への学習と削除 |
— Created 2017-01-22 by Shane Stanley use AppleScript version "2.4" use framework "Foundation" use framework "AppKit" use scripting additions –http://piyocast.com/as/archives/4635 –スペルチェック辞書への学習 set theWord to "piyomaru" set theChecker to current application’s NSSpellChecker’s sharedSpellChecker() theChecker’s learnWord:theWord set knewIt to theChecker’s hasLearnedWord:theWord –> true –スペルチェック辞書からの削除 theChecker’s unlearnWord:theWord set knowsItNow to theChecker’s hasLearnedWord:theWord return {knewIt, knowsItNow} –> {true, false} |
ロシア語(ru)のシステムスペルチェック辞書を指定して学習
AppleScript名:ロシア語(ru)のシステムスペルチェック辞書を指定して学習 |
— Created 2017-05-12 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use framework "Foundation" use framework "AppKit" use scripting additions –http://piyocast.com/as/archives/4635 set theChecker to current application’s NSSpellChecker’s sharedSpellChecker() set langList to (theChecker’s availableLanguages()) as list –> {"en", "en_GB", "en_CA", "en_IN", "en_SG", "en_AU", "en_JP", "fr", "da", "de", "es", "it", "nl", "nb", "pl", "pt_BR", "pt_PT", "fi", "sv", "tr", "ru", "ko"} set curCheckerLang to (theChecker’s |language|()) as string –> "en_GB" set aWord to "Su-35" theChecker’s setLanguage:"ru" theChecker’s learnWord:aWord set knewIt to theChecker’s hasLearnedWord:aWord –> true set curCheckerLang to (theChecker’s |language|()) as string –> "ru" |
テキストをTTSで読み上げて所要時間を算出 v2.1(CotEditor版)
指定のテキストをTTS(Text To Speech)音声で読み上げ、読み上げ所要時間を計算するAppleScriptです。
実時間をかけて読み上げるのではなく、ファイルに対して音声レンダリングしたデータを書き込む動作をsayコマンドで行うため、読み上げ実時間よりも短い時間で動作を完了します。
読み上げ速度を遅いパターンと速いパターンで個別に音声レンダリングして所要時間のシミュレーションを行ったり、Keynoteのプレゼン資料のすべてのテキスト要素を読み上げ所要時間のシミュレーションを行なって、資料の枚数が多すぎるとか少なすぎるといった判断を行なっています(与えられた時間よりも多い資料を発表することはできないので)。
とくに、プレゼン発表に不慣れな人は発表資料のページを多くしがち&1ページあたりの文字数を多くしがちなので、sayコマンドによる読み上げシミュレーションで「この発表時間に対して要素が多すぎるのでは?」といった話をします。
AppleScript名:テキストをTTSで読み上げて所要時間を算出 v2.1(CotEditor版) |
— Created 2018-01-10 by Takaaki Naganoya — 2018 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "AVFoundation" use framework "AppKit" –http://piyocast.com/as/archives/5113 property |NSURL| : a reference to current application’s |NSURL| property NSDate : a reference to current application’s NSDate property NSUUID : a reference to current application’s NSUUID property NSFileManager : a reference to current application’s NSFileManager property AVAudioPlayer : a reference to current application’s AVAudioPlayer property NSDateFormatter : a reference to current application’s NSDateFormatter property NSSpeechSynthesizer : a reference to current application’s NSSpeechSynthesizer set str3 to getEditorText() of me if str3 = false then return set aVoice to "Kyoko" –Check existence of TTS Voice name set vList to retAvailableTTSnames() of me if aVoice is not in vList then error "Wrong TTS Voice Name" set d1 to readTextByTTSVoiceAndReturnDuration(str3, aVoice, 180) of me –aSpeedRate is "Words per minute. 180 to 220" set d2 to readTextByTTSVoiceAndReturnDuration(str3, aVoice, 220) of me set outStr to (formatHMS(d1) of me & "/180 words per minute") & return & (formatHMS(d2) of me & "/220 words per minute") & return tell application "CotEditor" activate write to console outStr end tell on readTextByTTSVoiceAndReturnDuration(aStr as string, aVoice as string, aSpeedRate as integer) set aUUID to NSUUID’s UUID()’s UUIDString() as string –set aPath to (((path to temporary items from user domain) as string) & aUUID & ".aif") set aPath to (((path to desktop) as string) & aUUID & ".aif") set aPOSIX to POSIX path of aPath tell current application say aStr using aVoice saving to (aPOSIX) speaking rate aSpeedRate without waiting until completion end tell repeat 100000 times set aExt to NSFileManager’s defaultManager()’s fileExistsAtPath:aPOSIX if aExt as boolean = true then exit repeat delay "0.001" as real end repeat if aExt = false then error "No Sound file" set aDur to getDuration(aPath as alias) of me try do shell script "rm -f " & quoted form of POSIX path of aPath end try return aDur as real end readTextByTTSVoiceAndReturnDuration on getDuration(aFile) set aURL to |NSURL|’s fileURLWithPath:(POSIX path of aFile) repeat 1000 times set aAudioPlayer to AVAudioPlayer’s alloc()’s initWithContentsOfURL:aURL |error|:(missing value) set aRes to aAudioPlayer’s prepareToPlay() if aRes as boolean = true then exit repeat delay 0.5 end repeat if aRes = false then error "TTS sound output failed" set channelCount to aAudioPlayer’s numberOfChannels() set aDuration to aAudioPlayer’s duration() return aDuration as real end getDuration on retAvailableTTSnames() set outList to {} set aList to NSSpeechSynthesizer’s availableVoices() set bList to aList as list repeat with i in bList set j to contents of i set aInfo to (NSSpeechSynthesizer’s attributesForVoice:j) set aInfoRec to aInfo as record set aName to VoiceName of aInfoRec set the end of outList to aName end repeat return outList end retAvailableTTSnames on formatHMS(aTime) set aDate to NSDate’s dateWithTimeIntervalSince1970:aTime set aFormatter to NSDateFormatter’s alloc()’s init() —This formatter text is localized in Japanese. if aTime < hours then aFormatter’s setDateFormat:"mm分ss秒" else if aTime < days then aFormatter’s setDateFormat:"HH時間mm分ss秒" else aFormatter’s setDateFormat:"DD日HH時間mm分ss秒" end if set timeStr to (aFormatter’s stringFromDate:aDate) as string return timeStr end formatHMS on getEditorText() tell application "CotEditor" if (count every document) = 0 then return false tell front document return contents end tell end tell end getEditorText |
システムにインストールされているTTS VoiceのID一覧を取得する
AppleScript名:システムにインストールされているTTS VoiceのID一覧を取得する |
— Created 2017-03-28 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "AppKit" set vList to current application’s NSSpeechSynthesizer’s availableVoices() as list –> {"com.apple.speech.synthesis.voice.Alex", "com.apple.speech.synthesis.voice.alice", "com.apple.speech.synthesis.voice.allison.premium", "com.apple.speech.synthesis.voice.alva", "com.apple.speech.synthesis.voice.amelie", "com.apple.speech.synthesis.voice.anna.premium", "com.apple.speech.synthesis.voice.audrey.premium", "com.apple.speech.synthesis.voice.ava.premium", "com.apple.speech.synthesis.voice.carmit", "com.apple.speech.synthesis.voice.damayanti", "com.apple.speech.synthesis.voice.daniel.premium", "com.apple.speech.synthesis.voice.diego", "com.apple.speech.synthesis.voice.ellen",……} |
OSにインストールされているTTS Voiceのうち指定言語をサポートするものを返す
AppleScript名:OSにインストールされているTTS Voiceのうち指定言語をサポートするものを返す |
— Created 2017-03-28 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "AppKit" set aLoc to (current application’s NSLocale’s currentLocale()’s identifier()) as string –> "ja_JP" set vList to getTTSVoiceNameWithLanguage(aLoc) of me –> {"Kyoko", "Otoya"} set vIDs to getTTSVoiceIDWithLanguage(aLoc) of me –> {"com.apple.speech.synthesis.voice.kyoko.premium", "com.apple.speech.synthesis.voice.otoya.premium"} set anID to getTTSVoiceIDWithName("Kyoko") of me –> {"com.apple.speech.synthesis.voice.kyoko.premium"} set anAge to getTTSVoiceAgeWithName("Otoya") of me –> 35 on getTTSVoiceNameWithLanguage(voiceLang) set outArray to current application’s NSMutableArray’s arrayWithObject:{} –Make Installed Voice List set aList to current application’s NSSpeechSynthesizer’s availableVoices() set bList to aList as list repeat with i in bList set j to contents of i set aDIc to (current application’s NSSpeechSynthesizer’s attributesForVoice:j) (outArray’s addObject:aDIc) end repeat set aPredicate to current application’s NSPredicate’s predicateWithFormat_("VoiceLocaleIdentifier == %@", voiceLang) set filteredArray to outArray’s filteredArrayUsingPredicate:aPredicate set aResList to (filteredArray’s valueForKey:"VoiceName") as list return aResList end getTTSVoiceNameWithLanguage on getTTSVoiceIDWithLanguage(voiceLang) set outArray to current application’s NSMutableArray’s arrayWithObject:{} set aList to current application’s NSSpeechSynthesizer’s availableVoices() set bList to aList as list repeat with i in bList set j to contents of i set aDIc to (current application’s NSSpeechSynthesizer’s attributesForVoice:j) (outArray’s addObject:aDIc) end repeat set aPredicate to current application’s NSPredicate’s predicateWithFormat_("VoiceLocaleIdentifier == %@", voiceLang) set filteredArray to outArray’s filteredArrayUsingPredicate:aPredicate set aResList to (filteredArray’s valueForKey:"VoiceIdentifier") as list return aResList end getTTSVoiceIDWithLanguage on getTTSVoiceIDWithName(voiceName) set outArray to current application’s NSMutableArray’s arrayWithObject:{} set aList to current application’s NSSpeechSynthesizer’s availableVoices() set bList to aList as list repeat with i in bList set j to contents of i set aDIc to (current application’s NSSpeechSynthesizer’s attributesForVoice:j) (outArray’s addObject:aDIc) end repeat set aPredicate to current application’s NSPredicate’s predicateWithFormat_("VoiceName == %@", voiceName) set filteredArray to outArray’s filteredArrayUsingPredicate:aPredicate set aResList to (filteredArray’s valueForKey:"VoiceIdentifier") as list return aResList end getTTSVoiceIDWithName on getTTSVoiceAgeWithName(voiceName) set outArray to current application’s NSMutableArray’s arrayWithObject:{} set aList to current application’s NSSpeechSynthesizer’s availableVoices() set bList to aList as list repeat with i in bList set j to contents of i set aDIc to (current application’s NSSpeechSynthesizer’s attributesForVoice:j) (outArray’s addObject:aDIc) end repeat set aPredicate to current application’s NSPredicate’s predicateWithFormat_("VoiceName == %@", voiceName) set filteredArray to outArray’s filteredArrayUsingPredicate:aPredicate set aResList to (filteredArray’s valueForKey:"VoiceAge") as list set anItem to first item of aResList if anItem = missing value then return 0 return anItem as integer end getTTSVoiceAgeWithName |
TTS Voiceを言語と性別で抽出
AppleScript名:TTS Voiceを言語と性別で抽出 |
— Created 2017-03-28 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "AppKit" set aLoc to (current application’s NSLocale’s currentLocale()’s identifier()) as string –> "ja_JP" set vList to getTTSVoiceNameWithLanguageAndGender(aLoc, "Male") of me –> {"Otoya"} set vList to getTTSVoiceNameWithLanguageAndGender(aLoc, "Female") of me –> {"Kyoko"} set vList to getTTSVoiceNameWithLanguageAndGender("en_US", "Male") of me –> {"Alex", "Bruce", "Fred", "Junior", "Ralph", "Tom"} on getTTSVoiceNameWithLanguageAndGender(voiceLang, aGen) if aGen = "Male" then set aGender to "VoiceGenderMale" else if aGen = "Female" then set aGender to "VoiceGenderFemale" end if set outArray to current application’s NSMutableArray’s new() set aList to current application’s NSSpeechSynthesizer’s availableVoices() set bList to aList as list repeat with i in bList set j to contents of i set aDIc to (current application’s NSSpeechSynthesizer’s attributesForVoice:j) (outArray’s addObject:aDIc) end repeat set aPredicate to current application’s NSPredicate’s predicateWithFormat_("VoiceLocaleIdentifier == %@ && VoiceGender== %@", voiceLang, aGender) set filteredArray to outArray’s filteredArrayUsingPredicate:aPredicate set aResList to (filteredArray’s valueForKey:"VoiceName") as list return aResList end getTTSVoiceNameWithLanguageAndGender |
すべてのTTS VoiceからLocale情報を抽出し、指定LocaleのTTS Voice名を取得
AppleScript名:すべてのTTS VoiceからLocale情報を抽出し、指定LocaleのTTS Voice名を取得 |
— Created 2015-08-25 by Takaaki Naganoya — Modified 2015-08-26 by Shane Stanley, Takaaki Naganoya — 2015 Piyomaru Software use AppleScript version "2.5" use scripting additions use framework "Foundation" use framework "AppKit" –すべてのTTS VoiceからIdentifier情報を抽出してユニーク化 set v1Res to getLocaleICodeFromTTSVoices() set vRes to choose from list v1Res with prompt "Select Locale" set v2Res to getTTSVoiceNameWithLanguage(first item of vRes) of me on getLocaleICodeFromTTSVoices() set aResList to getAttributeFromTTSVoices("VoiceLocaleIdentifier") of me return aResList as list end getLocaleICodeFromTTSVoices on getAttributeFromTTSVoices(anAttribute) set outArray to current application’s NSMutableArray’s new() set aList to current application’s NSSpeechSynthesizer’s availableVoices() set bList to aList as list repeat with i in bList set j to contents of i set aDict to (current application’s NSSpeechSynthesizer’s attributesForVoice:j) (outArray’s addObject:aDict) end repeat set aResArray to (outArray’s valueForKey:anAttribute) set aSet to current application’s NSMutableSet’s setWithArray:aResArray set aResList to aSet’s allObjects() return aResList as list end getAttributeFromTTSVoices on getTTSVoiceNameWithLanguage(voiceLang) set outArray to current application’s NSMutableArray’s new() set aList to current application’s NSSpeechSynthesizer’s availableVoices() set bList to aList as list repeat with i in bList set j to contents of i set aDIc to (current application’s NSSpeechSynthesizer’s attributesForVoice:j) (outArray’s addObject:aDIc) end repeat set aPredicate to current application’s NSPredicate’s predicateWithFormat_("VoiceLocaleIdentifier == %@", voiceLang) set filteredArray to outArray’s filteredArrayUsingPredicate:aPredicate set aResList to (filteredArray’s valueForKey:"VoiceName") as list return aResList end getTTSVoiceNameWithLanguage |
すべてのTTS VoiceからLanguage情報を抽出してユニーク化
AppleScript名:すべてのTTS VoiceからLanguage情報を抽出してユニーク化 |
— Created 2015-08-25 by Takaaki Naganoya — Modified 2015-08-26 by Shane Stanley, Takaaki Naganoya — 2015 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "AppKit" set v1Res to getLocaleICodeFromTTSVoices() –> {"fr_FR", "zh_TW", "it_IT", "en_ZA", "es_AR", "ko_KR", "ro_RO", "en_IN", "fr_CA", "hi_IN", "da_DK", "en-scotland", "pt_BR", "zh_CN", "sv_SE", "es_ES", "ar_SA", "hu_HU", "en_GB", "ja_JP", "fi_FI", "zh_HK", "tr_TR", "nb_NO", "pl_PL", "id_ID", "cs_CZ", "el_GR", "he_IL", "ru_RU", "de_DE", "en_AU", "nl_BE", "pt_PT", "th_TH", "sk_SK", "en_US", "en_IE", "nl_NL", "es_MX"} set v2Res to getLanguageCodeFromTTSVoices() –> {"nl-NL", "id", "fr-FR", "it-IT", "es-419", "ko-KR", "ro-RO", "fr-CA", "hi-IN", "da-DK", "pt-BR", "sv-SE", "es-ES", "hu-HU", "en-GB", "ja-JP", "fi-FI", "tr-TR", "ar", "nb-NO", "pl-PL", "cs-CZ", "el-GR", "he-IL", "ru-RU", "zh-Hans", "de-DE", "en-AU", "zh-Hant", "nl-BE", "pt-PT", "th-TH", "sk-SK", "en-US", "en-IE"} on getLanguageCodeFromTTSVoices() set aResList to getAttributeFromTTSVoices("VoiceLanguage") of me return aResList as list end getLanguageCodeFromTTSVoices on getLocaleICodeFromTTSVoices() set aResList to getAttributeFromTTSVoices("VoiceLocaleIdentifier") of me return aResList as list end getLocaleICodeFromTTSVoices on getAttributeFromTTSVoices(anAttribute) set outArray to current application’s NSMutableArray’s new() set aList to current application’s NSSpeechSynthesizer’s availableVoices() set bList to aList as list repeat with i in bList set j to contents of i set aDict to (current application’s NSSpeechSynthesizer’s attributesForVoice:j) (outArray’s addObject:aDict) end repeat set aResArray to (outArray’s valueForKey:anAttribute) set aSet to current application’s NSMutableSet’s setWithArray:aResArray set aResList to aSet’s allObjects() return aResList as list end getAttributeFromTTSVoices |
TTS Voice名一覧を取得
AppleScript名:TTS Voice名一覧を取得 |
use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "AppKit" property NSSpeechSynthesizer : a reference to current application’s NSSpeechSynthesizer set vList to retAvailableTTSnames() of me –> {"Agnes", "Albert", "Alex", "Alice", "Allison", "Alva", "Amelie", "Anna", "Audrey", "Ava", "Bad News", "Bahh", "Bells", "Boing", "Bruce", "Bubbles", "Carmit", "Cellos", "Damayanti", "Daniel", "Deranged", "Diego", "Ellen", "Emily", "Fiona", "Fred", "Good News", "Hysterical", "Ioana", "Jill", "Joana", "Jorge", "Juan", "Junior", "Kanya", "Karen", "Kate", "Kathy", "Kyoko", "Laura", "Lee", "Lekha", "Luca", "Luciana", "Maged", "Mariska", "Mei-Jia", "Melina", "Milena", "Moira", "Monica", "Nora", "Otoya", "Paulina", "Pipe Organ", "Princess", "Ralph", "Samantha", "Sara", "Satu", "Serena", "Sin-ji", "Tessa", "Thomas", "Ting-Ting", "Tom", "Trinoids", "Veena", "Vicki", "Victoria", "Whisper", "Xander", "Yelda", "Yuna", "Yuri", "Zarvox", "Zosia", "Zuzana"} on retAvailableTTSnames() set outList to {} set aList to NSSpeechSynthesizer’s availableVoices() set bList to aList as list repeat with i in bList set j to contents of i set aInfo to (NSSpeechSynthesizer’s attributesForVoice:j) set aInfoRec to aInfo as record set aName to VoiceName of aInfoRec set the end of outList to aName end repeat return outList end retAvailableTTSnames |
InputManagerのじっけん
–> InputManager.framework (To ~/Library/Frameworks)
AppleScript名:InputManagerのじっけん |
— Created 2017-01-22 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "InputManager" set cList to current application’s CSInputSource’s all() –> (NSArray) {(CSInputSource) <CSInputSource: 0x60000000d310>, (CSInputSource) <CSInputSource: 0x60000000f580>, (CSInputSource) <CSInputSource: 0x60000000bd30>, (CSInputSource) <CSInputSource: 0x600000216d20>, (CSInputSource) <CSInputSource: 0x6000002168d0>, (CSInputSource) <CSInputSource: 0x600000216c50>, (CSInputSource) <CSInputSource: 0x600000012620>, (CSInputSource) <CSInputSource: 0x60000000b010>, (CSInputSource) <CSInputSource: 0x600000217010>} set dList to (cList’s valueForKey:"localizedName") as list –> {"ひらがな", "英字", "カタカナ", "日本語", "かなパレット", "com.apple.PressAndHold", "絵文字と記号", "キーボードビューア", "EmojiFunctionRowIM_Extension"} set c1 to (current application’s CSInputSource’s currentKeyboard()’s localizedName()) as string –> "ひらがな" –> "英字" set c2 to (current application’s CSInputSource’s currentKeyboardLayout()’s localizedName()) as string –> "U.S." set err1 to (current application’s CSInputSource’s forLanguage:"ja")’s |select|() log err1 set err2 to (current application’s CSInputSource’s forLanguage:"en_US")’s |select|() log err2 |
IMのメニュー表示名を取得する
AppleScript名:IMのメニュー表示名を取得する |
— Created 2017-01-22 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "InputManager" –https://github.com/jensnockert/input-manager set cList to (current application’s CSInputSource’s all()’s valueForKey:"localizedName") as list –> {"ひらがな", "英字", "カタカナ", "日本語", "かなパレット", "com.apple.PressAndHold", "絵文字と記号", "キーボードビューア", "EmojiFunctionRowIM_Extension"} |
InputMethodで現在選択中のIM名を文字列で取得する
AppleScript名:InputMethodで現在選択中のIM名を文字列で取得する |
— Created 2017-01-22 22:11:33 +0900 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "InputManager" set c2 to (current application’s CSInputSource’s mInputSource()) –> "英字" –> "ひらがな" –> "カタカナ" |
keychainLib
オープンソースのSAMKeychainを用いてキーチェーンにアクセスし、指定項目のパスワードの取得、新規項目の作成、キーチェーン項目の検索、アカウントの取得、項目の削除などを行うAppleScriptです。
# Apitoreは2019年5月31日をもってサービスを終了
オープンソースのSAMKeychainをCocoa Framework化したkeychainLib.frameworkをインストールを呼び出しています。
かつて、Mac OS X上にはKeychain ScriptingというAppleScriptから呼び出す専用の補助プログラムがOSに標準装備されていましたが、OS X 10.7で廃止になりました。以後、OS X 10.9までshell commandのsecurityコマンドを呼び出すことが必要となっていましたが、OS X 10.10でAppleScriptがCocoa呼び出しに対応したため、このような使い方ができるようになった次第です。
AppleScript名:keychainLib |
— Created 2016-12-02 by Takaaki Naganoya — 2016 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "SSKeychain" –https://github.com/soffes/sskeychain property kSSKeychainServiceName : "SSToolkitTestService" property kSSKeychainAccountName : "SSToolkitTestAccount" property kSSKeychainPassword : "SSToolkitTestPassword" property kSSKeychainLabel : "SSToolkitLabel" set kRes to getPasswordForAccount("apitore API Key", "maro@piyocast.com") of me –> "xxXXXxxX-XxXx-XXXX-xXXX-XXxXXxxXxxXx" –Get Password on getPasswordForAccount(aServiceName as string, anAccount as string) set bQuery to current application’s SSKeychainQuery’s alloc()’s init() bQuery’s setService:aServiceName bQuery’s setAccount:anAccount bQuery’s setPassword:(missing value) set bRes to (bQuery’s fetch:(missing value)) as boolean return (bQuery’s |password|()) as string end getPasswordForAccount — New item on makeNewItem(aPassword as string, aServiceName as string, anAccount as string, aLabel as string) set aQuery to current application’s SSKeychainQuery’s alloc()’s init() aQuery’s setPassword:aPassword aQuery’s setService:aServiceName aQuery’s setAccount:anAccount aQuery’s setLabel:aLabel return (aQuery’s |save|:(missing value)) as boolean end makeNewItem — Look up on lookUpPassWord(aServiceName, anAccount) set bQuery to current application’s SSKeychainQuery’s alloc()’s init() bQuery’s setService:aServiceName bQuery’s setAccount:anAccount bQuery’s setPassword:(missing value) set bRes to (bQuery’s fetch:(missing value)) as boolean return (bQuery’s |password|() ≠ missing value) end lookUpPassWord — Search for all accounts on getAllAccounts() set cQuery to current application’s SSKeychainQuery’s alloc()’s init() return (cQuery’s fetchAll:(missing value)) as list –> (NSArray) {{mdat:(NSDate) 2010-02-23 08:36:19 +0000, cdat:(NSDate) 2010-02-23 08:36:19 +0000, acct:"GoogleJapaneseInput", class:"genp", svce:"GoogleJapaneseInput", labl:"GoogleJapaneseInput", crtr:9999999999}, …… end getAllAccounts — Check accounts for service on getAccount(aServiceName) set cQuery to current application’s SSKeychainQuery’s alloc()’s init() cQuery’s setService:aServiceName return (cQuery’s fetchAll:(missing value)) as list –> (NSArray) {{mdat:(NSDate) 2016-03-02 13:54:54 +0000, cdat:(NSDate) 2016-03-02 13:44:19 +0000, svce:"SSToolkitTestService", acct:"SSToolkitTestAccount", class:"genp", labl:"SSToolkitLabel"}} end getAccount — Delete on deleteKeychain(aServiceName, anAccountName) set dQuery to current application’s SSKeychainQuery’s alloc()’s init() dQuery’s setService:aServiceName dQuery’s setAccount:anAccountName return (dQuery’s deleteItem:(missing value)) as boolean end deleteKeychain –Test Password Object on testPasswordObject() set eQuery to current application’s SSKeychainQuery’s alloc()’s init() eQuery’s setService:kSSKeychainServiceName eQuery’s setAccount:kSSKeychainAccountName set eDic1 to current application’s NSDictionary’s dictionaryWithObjectsAndKeys_(42, "number", "Hello World", "string", missing value) eQuery’s setPasswordObject:eDic1 set fRes to (eQuery’s |save|:(missing value)) as boolean set fQuery to current application’s SSKeychainQuery’s alloc()’s init() fQuery’s setService:kSSKeychainServiceName fQuery’s setAccount:kSSKeychainAccountName fQuery’s setPassword:(missing value) fQuery’s fetch:(missing value) return {fQuery’s passwordObject(), eDic1} –> {(NSDictionary) {number:42, string:"Hello World"}, (NSDictionary) {number:42, string:"Hello World"}} end testPasswordObject |
指定のアプリケーションのURL Schemeを取得する
AppleScript名:指定のアプリケーションのURL Schemeを取得する |
— Created 2017-07-23 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use BridgePlus : script "BridgePlus" –http://piyocast.com/as/archives/4759 load framework set aP to choose file set aURLrec to getAppURLSchemes(aP) of me –> {appName:"Photos", appBundleID:"com.apple.Photos", urlScheme:{"photos"}} on getAppURLSchemes(aP) set aURL to current application’s |NSURL|’s fileURLWithPath:(POSIX path of aP) set aBundle to current application’s NSBundle’s bundleWithURL:aURL set aDict to aBundle’s infoDictionary() set appNameDat to (aDict’s valueForKey:"CFBundleName") as string set bundleIDat to (aDict’s valueForKey:"CFBundleIdentifier") as string set urlSchemes to (aDict’s valueForKey:"CFBundleURLTypes") if urlSchemes is not equal to missing value then set urlList to urlSchemes’s valueForKey:"CFBundleURLSchemes" set urlListFlat to (current application’s SMSForder’s arrayByFlattening:urlList) as list else set urlListFlat to {} end if set aRec to {appName:appNameDat, appBundleID:bundleIDat, urlScheme:urlListFlat} return aRec end getAppURLSchemes |