Menu

Skip to content
AppleScriptの穴
  • Home
  • Products
  • Books
  • Docs
  • Events
  • Forum
  • About This Blog
  • License
  • 仕事依頼

AppleScriptの穴

Useful & Practical AppleScript archive. Click '★Click Here to Open This Script' Link to download each AppleScript

タグ: 10.12savvy

Maps.appで開始地点と到着地点の住所を指定して経路表示 v3

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:Maps.appで開始地点と到着地点の住所を指定して経路表示 v3
— Created 2017-01-17 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

set aURL to "http://maps.apple.com/"
set aRec to {saddr:"中村橋駅", daddr:"よみうりホール"} –経路表示
set bURL to retURLwithParams(aURL as string, aRec as record)
open location bURL

on retURLwithParams(aBaseURL as string, aRec as record)
  set aDic to current application’s NSMutableDictionary’s dictionaryWithDictionary:aRec
  
  
set aKeyList to (aDic’s allKeys()) as list
  
set aValList to (aDic’s allValues()) as list
  
set aLen to length of aKeyList
  
set bLen to length of aValList
  
if aLen is not equal to bLen then return false
  
  
set qList to {}
  
repeat with i from 1 to aLen
    set aName to (contents of item i of aKeyList) as string
    
set aVal to (contents of item i of aValList) as string
    
set the end of qList to (current application’s NSURLQueryItem’s queryItemWithName:aName value:aVal)
  end repeat
  
  
set aComp to current application’s NSURLComponents’s alloc()’s initWithString:aBaseURL
  
aComp’s setQueryItems:qList
  
set aURL to (aComp’s |URL|()’s absoluteString()) as text
  
  
return aURL
end retURLwithParams

★Click Here to Open This Script 

com.apple.Maps

Posted in geolocation URL | Tagged 10.11savvy 10.12savvy 10.13savvy Maps | Leave a comment

Maps.appで住所検索表示 v4

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:Map.appで住所検索表示 v4
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

set aBaseURL to "http://maps.apple.com/"

set aParam to "東京都港区六本木6丁目10番1号" –Apple Japanの住所
set aRec to {q:aParam}
set cURL to retURLwithParams(aBaseURL, aRec) of me

tell application "Maps"
  open location cURL
end tell

on retURLwithParams(aBaseURL as string, aRec as record)
  set aDic to current application’s NSMutableDictionary’s dictionaryWithDictionary:aRec
  
  
set aKeyList to (aDic’s allKeys()) as list
  
set aValList to (aDic’s allValues()) as list
  
set aLen to length of aKeyList
  
set bLen to length of aValList
  
if aLen is not equal to bLen then return false
  
  
set qList to {}
  
repeat with i from 1 to aLen
    set aName to (contents of item i of aKeyList) as string
    
set aVal to (contents of item i of aValList) as string
    
set the end of qList to (current application’s NSURLQueryItem’s queryItemWithName:aName value:aVal)
  end repeat
  
  
set aComp to current application’s NSURLComponents’s alloc()’s initWithString:aBaseURL
  
aComp’s setQueryItems:qList
  
set aURL to (aComp’s |URL|()’s absoluteString()) as text
  
  
return aURL
end retURLwithParams

★Click Here to Open This Script 

com.apple.Maps

Posted in geolocation URL | Tagged 10.11savvy 10.12savvy 10.13savvy Maps | Leave a comment

Maps.appで緯度経度指定表示 v3

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:Map.appで緯度経度指定表示 v3
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

set aURL to "http://maps.apple.com/?ll=41.82459,140.7174504&t=m" –ラウンドワンスタジアム函館

open location aURL

★Click Here to Open This Script 

com.apple.Maps

Posted in geolocation | Tagged 10.11savvy 10.12savvy 10.13savvy Maps | 1 Comment

iTunesでAirPlayデバイスを指定

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:iTunesでAirPlayデバイスを指定
tell application "iTunes"
  set aList to properties of every AirPlay device
  
–> {{class:AirPlay device, id:27, index:1, name:"コンピュータ", persistent ID:"0000000000000000", active:false, available:true, kind:computer, protected:false, selected:true, supports audio:true, supports video:true, sound volume:100}, {class:AirPlay device, id:58366, index:2, name:"Apple TV", persistent ID:"00005855CA413D01", active:false, available:true, kind:Apple TV, network address:"58:55:ca:41:3d:01", protected:false, selected:false, supports audio:true, supports video:true, sound volume:100}}
  
  
set current AirPlay devices to AirPlay device "コンピュータ"
end tell

★Click Here to Open This Script 

iTunes Control

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy iTunes | Leave a comment

iTunesライブラリの曲のアーティスト名を集計

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:iTunesライブラリの曲のアーティスト名を集計
— Created 2017-01-07 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "iTunesLibrary"

set library to current application’s ITLibrary’s libraryWithAPIVersion:"1.0" |error|:(missing value)
if library is equal to missing value then return

set allTracks to library’s allMediaItems()
set allCount to allTracks’s |count|()

set anEnu to allTracks’s objectEnumerator()
set newArray to current application’s NSMutableArray’s alloc()’s init()

repeat
  set aPL to anEnu’s nextObject()
  
if aPL = missing value then exit repeat
  
try
    set aKind to (aPL’s mediaKind) as integer
    
    
if (aKind as integer) is equal to 2 then –Music, Song
      set plName to aPL’s artist’s |name| as string
      
set pl2Name to (my changeThis:" " toThat:"" inString:plName) –日本語アーティスト名で姓と名の間にスペースが入っているものがある(表記ゆらぎ)ので対策
      
newArray’s addObject:(pl2Name)
    end if
  on error
    set aLoc to (aPL’s location’s |path|()) as string
    
log aLoc
  end try
end repeat

set aRes to countItemsByItsAppearance(newArray) of me
–>  {​​​​​{​​​​​​​theName:"浜田省吾", ​​​​​​​numberOfTimes:442​​​​​}, ​​​​​{​​​​​​​theName:"B’z", ​​​​​​​numberOfTimes:379​​​​​}, ​​​​​{​​​​​​​theName:"渡辺岳夫・松山祐士", ​​​​​​​numberOfTimes:199​​​​​}, ​​​​​{​​​​​​​theName:"VariousArtists", ​​​​​​​numberOfTimes:192​​​​​}, ​​​​​{​​​​​​​theName:"菅野よう子", ​​​​​​​numberOfTimes:108​​​​​}, ​​​​​{​​​​​​​theName:"布袋寅泰", ​​​​​​​numberOfTimes:100​​​​​}, ​​​​​{​​​​​​​theName:"三枝成彰", ​​​​​​​numberOfTimes:95​​​​​}, ​​​​​{​​​​​​​theName:"宇多田ヒカル", ​​​​​​​numberOfTimes:94​​​​​}, ​​​​​{​​​​​​​theName:"宮川泰", ​​​​​​​numberOfTimes:81​​​​​}, ​​​​​{​​​​​​​theName:"MichaelJackson", ​​​​​​​numberOfTimes:78​​​​​}, ​​​​​{​​​​​​​theName:"稲葉浩志", ​​​​​​​numberOfTimes:73​​​​​}, ​​​​​…

–出現回数で集計
on countItemsByItsAppearance(aList)
  set aSet to current application’s NSCountedSet’s alloc()’s initWithArray:aList
  
set bArray to current application’s NSMutableArray’s array()
  
set theEnumerator to aSet’s objectEnumerator()
  
  
repeat
    set aValue to theEnumerator’s nextObject()
    
if aValue is missing value then exit repeat
    
bArray’s addObject:(current application’s NSDictionary’s dictionaryWithObjects:{aValue, (aSet’s countForObject:aValue)} forKeys:{"theName", "numberOfTimes"})
  end repeat
  
  
–出現回数(numberOfTimes)で降順ソート
  
set theDesc to current application’s NSSortDescriptor’s sortDescriptorWithKey:"numberOfTimes" ascending:false
  
bArray’s sortUsingDescriptors:{theDesc}
  
  
return bArray as list
end countItemsByItsAppearance

on changeThis:findString toThat:repString inString:someText
  set theString to current application’s NSString’s stringWithString:someText
  
set theString to theString’s stringByReplacingOccurrencesOfString:findString withString:repString options:(current application’s NSRegularExpressionSearch) range:{location:0, |length|:length of someText}
  
return theString as text
end changeThis:toThat:inString:

★Click Here to Open This Script 

iTunes Control

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy ITLibrary iTunes | Leave a comment

iTunesライブラリのファイル種別集計

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:iTunesライブラリのファイル種別集計
— Created 2016-11-02 by Takaaki Naganoya
— 2016 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "iTunesLibrary"
–http://piyocast.com/as/archives/4301

set library to current application’s ITLibrary’s libraryWithAPIVersion:"1.0" |error|:(missing value)
if library is equal to missing value then return

set playLists to library’s allPlaylists()
set gArray to library’s allMediaItems()’s |kind|
set aRes to countItemsByItsAppearance(gArray) of me
–> {{theName:"AAC オーディオファイル", numberOfTimes:3273}, {theName:"MPEG オーディオファイル", numberOfTimes:1768}, {theName:"購入した AAC オーディオファイル", numberOfTimes:1299}, {theName:"保護された AAC オーディオファイル", numberOfTimes:1102}, {theName:missing value, numberOfTimes:331}, {theName:"保護された MPEG-4 オーディオストリーム", numberOfTimes:183}, {theName:"MPEG オーディオストリーム", numberOfTimes:71}, {theName:"Apple ロスレス・オーディオファイル", numberOfTimes:36}, {theName:"QuickTime ムービーファイル", numberOfTimes:35}, {theName:"保護されたブック", numberOfTimes:28}, {theName:"AIFF オーディオファイル", numberOfTimes:21}, {theName:"MPEG-4 ビデオファイル", numberOfTimes:17}, {theName:"着信音", numberOfTimes:17}, {theName:"保護された MPEG-4 ビデオファイル", numberOfTimes:14}, {theName:"PDF 書類", numberOfTimes:11}, {theName:"ブック", numberOfTimes:8}, {theName:"購入したブック", numberOfTimes:6}, {theName:"iPhone/iPod touch/iPad App", numberOfTimes:5}, {theName:"購入した MPEG-4 ビデオファイル", numberOfTimes:5}, {theName:"インターネットオーディオストリーム", numberOfTimes:3}, {theName:"WAV オーディオファイル", numberOfTimes:2}, {theName:"iTunes Extras", numberOfTimes:2}, {theName:"iPhone/iPod touch App", numberOfTimes:1}, {theName:"QuickTime ムービー URL", numberOfTimes:1}, {theName:"Purchased AAC audio file", numberOfTimes:1}}

–出現回数で集計
on countItemsByItsAppearance(aList)
  set aSet to current application’s NSCountedSet’s alloc()’s initWithArray:aList
  
set bArray to current application’s NSMutableArray’s array()
  
set theEnumerator to aSet’s objectEnumerator()
  
  
repeat
    set aValue to theEnumerator’s nextObject()
    
if aValue is missing value then exit repeat
    
bArray’s addObject:(current application’s NSDictionary’s dictionaryWithObjects:{aValue, (aSet’s countForObject:aValue)} forKeys:{"theName", "numberOfTimes"})
  end repeat
  
  
–出現回数(numberOfTimes)で降順ソート
  
set theDesc to current application’s NSSortDescriptor’s sortDescriptorWithKey:"numberOfTimes" ascending:false
  
bArray’s sortUsingDescriptors:{theDesc}
  
  
return bArray as list
end countItemsByItsAppearance

★Click Here to Open This Script 

iTunes Control

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy ITLibrary iTunes | Leave a comment

iTunesライブラリのジャンル集計

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:iTunesライブラリのジャンル集計
— Created 2016-11-02 by Takaaki Naganoya
— 2016 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "iTunesLibrary"
–http://piyocast.com/as/archives/4301

set library to current application’s ITLibrary’s libraryWithAPIVersion:"1.0" |error|:(missing value)
if library is equal to missing value then return

set playLists to library’s allPlaylists()
set gArray to library’s allMediaItems()’s genre
set aRes to countItemsByItsAppearance(gArray) of me
–> {{theName:"サウンドトラック", numberOfTimes:1722}, {theName:"ロック", numberOfTimes:956}, {theName:"Podcast", numberOfTimes:721}, {theName:"クラシック", numberOfTimes:540}, {theName:"ポップ", numberOfTimes:529}, {theName:"J-Pop", numberOfTimes:382}, {theName:"アニメ", numberOfTimes:332}, {theName:missing value, numberOfTimes:287}, {theName:"Pop", numberOfTimes:279}, {theName:"社会/文化", numberOfTimes:279}, {theName:"World", numberOfTimes:218}, {theName:"ジャズ", numberOfTimes:188}, {theName:"Soundtrack", numberOfTimes:188}, {theName:"エレクトロニック", numberOfTimes:170}, {theName:"Classical", numberOfTimes:166}, {theName:"iTunes U", numberOfTimes:155}, {theName:"Rock", numberOfTimes:148}, {theName:"R&B", numberOfTimes:125}, {theName:"ニューエイジ", numberOfTimes:104}, {theName:"Unclassifiable", numberOfTimes:81}, {theName:"歌謡曲", numberOfTimes:58}, {theName:"オルタナティブ", numberOfTimes:58}, {theName:"Children’s", numberOfTimes:57}, {theName:"Holiday", numberOfTimes:38}, {theName:"Data", numberOfTimes:32}, {theName:"イージーリスニング", numberOfTimes:31}, {theName:"ワールド", numberOfTimes:30}, {theName:"ヴォーカル", numberOfTimes:29}, {theName:"ヒップホップ/ ラップ", numberOfTimes:24}, {theName:"Anime", numberOfTimes:23}, {theName:"フォーク", numberOfTimes:19}, {theName:"soundtrack", numberOfTimes:19}, {theName:"ブルース", numberOfTimes:15}, {theName:"ディズニー", numberOfTimes:15}, {theName:"シンガーソングライター", numberOfTimes:15}, {theName:"Easy Listening", numberOfTimes:14}, {theName:"ラテン", numberOfTimes:14}, {theName:"個人ジャーナル", numberOfTimes:14}, {theName:"Electronica/Dance", numberOfTimes:14}, {theName:"J-POP", numberOfTimes:9}, {theName:"New Age", numberOfTimes:9}, {theName:"アクション/アドベンチャー", numberOfTimes:9}, {theName:"ダンス", numberOfTimes:9}, {theName:"マンガ", numberOfTimes:7}, {theName:"演歌", numberOfTimes:7}, {theName:"プログラミング", numberOfTimes:7}, {theName:"Video", numberOfTimes:5}, {theName:"ホリデー", numberOfTimes:5}, {theName:"青年", numberOfTimes:5}, {theName:"キッズ/ファミリー", numberOfTimes:5}, {theName:"カントリー", numberOfTimes:4}, {theName:"R&B/ソウル", numberOfTimes:4}, {theName:"科学/医学", numberOfTimes:4}, {theName:"ビジネス", numberOfTimes:3}, {theName:"Latin", numberOfTimes:3}, {theName:"ヒップホップ/ラップ", numberOfTimes:3}, {theName:"チルドレン・ミュージック", numberOfTimes:3}, {theName:"#NIPPONSEI @ IRC.MIRCX.COM", numberOfTimes:2}, {theName:"コメディ", numberOfTimes:2}, {theName:"Technology", numberOfTimes:2}, {theName:"R&B/ソウル", numberOfTimes:2}, {theName:"ファンタジー", numberOfTimes:2}, {theName:"ユーティリティ", numberOfTimes:2}, {theName:"Vocal", numberOfTimes:2}, {theName:"ドラマ", numberOfTimes:2}, {theName:"社会科学", numberOfTimes:1}, {theName:"グラフィックノベル", numberOfTimes:1}, {theName:"コンピュータ/テクノロジー", numberOfTimes:1}, {theName:"伝記/自叙伝", numberOfTimes:1}, {theName:"女性", numberOfTimes:1}, {theName:"科学/自然", numberOfTimes:1}, {theName:"その他", numberOfTimes:1}, {theName:"児童書フィクション", numberOfTimes:1}, {theName:"業界/職業", numberOfTimes:1}, {theName:"レゲエ", numberOfTimes:1}, {theName:"Lifestyle & Home", numberOfTimes:1}, {theName:"マネジメント/リーダーシップ", numberOfTimes:1}, {theName:"スポークンワード", numberOfTimes:1}, {theName:"Dance", numberOfTimes:1}, {theName:"インストゥルメンタル", numberOfTimes:1}, {theName:"ライトノベル", numberOfTimes:1}, {theName:"SF/ファンタジー", numberOfTimes:1}, {theName:"ソーシャルネットワーキング", numberOfTimes:1}, {theName:"コンピュータ", numberOfTimes:1}, {theName:"146", numberOfTimes:1}, {theName:"健康/フィットネス", numberOfTimes:1}, {theName:"148", numberOfTimes:1}, {theName:"Electronic", numberOfTimes:1}, {theName:"仕事効率化", numberOfTimes:1}, {theName:"ライフスタイル", numberOfTimes:1}, {theName:"フィクション/文学", numberOfTimes:1}, {theName:"NHK FM(東京)", numberOfTimes:1}, {theName:"Seattle Pacific University – Latin", numberOfTimes:1}, {theName:"インスピレーショナル", numberOfTimes:1}, {theName:"日本/アジア", numberOfTimes:1}, {theName:"ブック", numberOfTimes:1}, {theName:"Kayokyoku", numberOfTimes:1}, {theName:"Folk", numberOfTimes:1}, {theName:"Romance", numberOfTimes:1}}

–出現回数で集計
on countItemsByItsAppearance(aList)
  set aSet to current application’s NSCountedSet’s alloc()’s initWithArray:aList
  
set bArray to current application’s NSMutableArray’s array()
  
set theEnumerator to aSet’s objectEnumerator()
  
  
repeat
    set aValue to theEnumerator’s nextObject()
    
if aValue is missing value then exit repeat
    
bArray’s addObject:(current application’s NSDictionary’s dictionaryWithObjects:{aValue, (aSet’s countForObject:aValue)} forKeys:{"theName", "numberOfTimes"})
  end repeat
  
  
–出現回数(numberOfTimes)で降順ソート
  
set theDesc to current application’s NSSortDescriptor’s sortDescriptorWithKey:"numberOfTimes" ascending:false
  
bArray’s sortUsingDescriptors:{theDesc}
  
  
return bArray as list
end countItemsByItsAppearance

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy ITLibrary | Leave a comment

Googleで検索して結果を返す v2

Posted on 2月 6, 2018 by Takaaki Naganoya

Webブラウザを併用せず、Googleの検索エンジンに直接問い合わせを行い、結果をCocoaの機能を用いて検索結果URLの一覧を取得するAppleScriptです。

オリジナル v1はShane Stanleyが作成、あまりに洗練された処理内容に絶句しました。さらに、処理内容が内容だけに、Shaneから見せられて「掲載はちょっと検討させて」と返事をしてしまったほど。

他のプログラミング言語でも同様の実装例が見られたので、問題視されないレベルと判断して掲載しました。

ただ、その一方でオリジナル版からの改良も行い、オリジナルでは20件ぐらいだった検索件数の拡張を行なって100件までの検索が行えるようにしたものがこのv2です。

長期間かつ大量の検索をGoogleの検索エンジンに対して行う場合には、REST API経由で行なってください。

追記(2019/08/20)
しばらく動いていましたが、Google側のWeb表示の仕様が変わって検索できなくなりました。ただし、検索結果のNSXMLDocumentからのURL抽出処理を変更することで、対応は可能と思われます(やっていませんが)。REST APIのドキュメント化された仕様は変わらないため、検索を行うにはREST API経由のほうが安心です。

追記(2020)
CotEditorのPowerPackにこれの改訂版を入れてあり、CotEditorで選択中の語句でGoogle検索できるようにしてあります。これの動作状況で様子を見ているところです。

AppleScript名:Googleで検索して結果を返す v4
— Created 2017-03-31 by Shane Stanley
— Modified 2019-09-18 by Takaaki Naganoya
use AppleScript version "2.4"
use framework "Foundation"
use scripting additions

property theResult : {}

set theQuery to "戦場の絆"
set paramObj to {myQuery:theQuery, myMax:10}

my performSelectorOnMainThread:"searchByGoogle:" withObject:(paramObj) waitUntilDone:true
return my theResult
–> {"http://web.gundam-kizuna.jp/sp/",…….}

on searchByGoogle:paramObj
  set theQuery to myQuery of paramObj
  
set maxNum to myMax of paramObj
  
  
— build and escape query string
  
set theQuery to current application’s NSString’s stringWithString:theQuery
  
set theQuery to theQuery’s stringByReplacingOccurrencesOfString:space withString:"+"
  
set escQuery to theQuery’s stringByAddingPercentEncodingWithAllowedCharacters:(current application’s NSCharacterSet’s URLQueryAllowedCharacterSet())
  
  
— do search
  
set searchURLString to current application’s NSString’s stringWithFormat_("https://www.google.com/search?client=safari&rls=en&ie=UTF-8&oe=UTF-8&q=%@&complete=0&num=%@&as_qdr=all", escQuery, (maxNum as string))
  
set theURL to current application’s |NSURL|’s URLWithString:searchURLString
  
set {theData, theError} to current application’s NSData’s dataWithContentsOfURL:theURL options:0 |error|:(reference)
  
if theData = missing value then error (theError’s localizedDescription() as text)
  
  
— convert to XML
  
set {theXMLDoc, theError} to current application’s NSXMLDocument’s alloc()’s initWithData:theData options:(current application’s NSXMLDocumentTidyHTML) |error|:(reference)
  
if theXMLDoc = missing value then error (theError’s localizedDescription() as text)
  
  
–検索結果として返してくるclass要素名を固定で書かない方法を模索するべき?
  
  
— filter via XPath and predicate
  
set xpathStr to "//*[@class=\"kCrYT\"]/a/@href" –ここが問題
  
  
set {theNodes, theError} to theXMLDoc’s nodesForXPath:xpathStr |error|:(reference)
  
if theNodes = missing value then error (theError’s localizedDescription() as text)
  
set nodeStrings to (theNodes’s valueForKey:"stringValue")
  
set thePred to current application’s NSPredicate’s predicateWithFormat:"self BEGINSWITH ’/url?q=’"
  
set nodeStrings to nodeStrings’s filteredArrayUsingPredicate:thePred
  
  
— trim URL strings
  
set theURLStrings to {}
  
repeat with aString in nodeStrings
    set theOffset to (aString’s rangeOfString:"&")
    
set end of theURLStrings to (aString’s substringWithRange:{7, (theOffset’s location) – 7}) as text
  end repeat
  
  
set my theResult to theURLStrings
end searchByGoogle:

★Click Here to Open This Script 

Posted in Network Text | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

Safariのダウンロードフォルダを求めるv4

Posted on 2月 6, 2018 by Takaaki Naganoya

本ScriptはSafariのダウンロードフォルダのパスを求めるためのものですが、macOSおよびSafariのアップデートによって動かなくなりました。

現時点では設定値からダウンロードフォルダを知ることはできないようです。セキュリティ上「できては困る」という判断が行われたものでしょうか。

なので、Spotlightの機能を用いて、「Download」フォルダを検索し、見つかったものの一覧からユーザーに選んでもらうとか、デフォルト状態のDownloadフォルダを指定してみて存在しなかったらユーザーに選択してもらうといった方法になると思われます。

AppleScript名:Safariのダウンロードフォルダを求めるv4
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

getSafariDownloadFolder() of me
–> alias "Cherry:Users:me:Downloads:"

–By Phillip Aker, Mark J Reed
on getSafariDownloadFolder()
  set preferencesPath to POSIX path of (path to preferences)
  
set bundleId to bundle identifier of (info for (path to application "Safari"))
  
set safariPrefsFile to preferencesPath & bundleId & ".plist"
  
tell application "System Events" to set folderName to get value of property list item "DownloadsPath" of property list file safariPrefsFile
  
  
set pathString to current application’s NSString’s stringWithString:folderName
  
set dlPath to pathString’s stringByExpandingTildeInPath() as string
  
return (POSIX file dlPath) as alias
end getSafariDownloadFolder

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy System Events | 1 Comment

ダークモード/ライトモードの切り替え

Posted on 2月 6, 2018 by Takaaki Naganoya

Dark Modeのトグル切り替えを行うAppleScriptです。

System Eventsに問い合わせて、appearance preferencesのDark Modeがtrueならダークモード、Dark Modeがfalseならライトモード(通常モード)です。

# Mac App Store用アプリケーションの中で使うとリジェクトの原因になります

AppleScript名:ダークモードの検出 v2
tell application "System Events"
  tell appearance preferences
    set dark mode to not dark mode
  end tell
end tell

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy 10.14savvy System Events | Leave a comment

Safariの最前面のWindowに新規tabをURLを指定しつつ作成

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:Safariの最前面のWindowに新規tabをURLを指定しつつ作成
tell application "Safari"
  tell window 1
    make new tab with properties {URL:"http://piyocast.com/as/"}
  end tell
end tell

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy Safari | Leave a comment

最前面のウィンドウのタイトルを取得する2

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:最前面のウィンドウのタイトルを取得する2
set aTitle to getPageTitleOfFrontmostWindow()

on getPageTitleOfFrontmostWindow()
  tell application "Safari"
    if (count every window) = 0 then return false
    
tell window 1
      set aProp to properties
    end tell
    
set aDoc to document of aProp
    
set aText to name of aDoc
  end tell
  
return aText
end getPageTitleOfFrontmostWindow

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy Safari | Leave a comment

Safariで選択部分のテキストを取得する2

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:Safariで選択部分のテキストを取得する2
tell application "Safari"
  set aRes to do JavaScript "var selObj = window.getSelection();
  var selStr = (selObj).getRangeAt(0);
  unescape(selStr);"
in document 1
  
end tell

aRes

★Click Here to Open This Script 

Posted in JavaScript | Tagged 10.11savvy 10.12savvy 10.13savvy Safari | 6 Comments

Safariの最前面のドキュメントのテキストを取得するv2

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:Safariの最前面のドキュメントのテキストを取得するv2
–フレームを使っていないことが前提条件
tell application "Safari"
  set wCount to count every window
  
if wCount = 0 then
    display dialog "Safariでウィンドウがオープンされていません" buttons {"OK"} default button 1
    
return
  end if
  
  
tell front document
    set aURL to URL
    
–> http://piyocast.com/as/archives/155
    
    
set aTitle to name
    
–> "SafariでURLをローディング – AppleScirpt Hole"
    
    
–set aCon to text
    
–log aCon
  end tell
  
  
set aText to text of front document –本文テキスト
  
end tell

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy Safari | Leave a comment

SafariでURLをローディング

Posted on 2月 6, 2018 by Takaaki Naganoya

本処理は最近のSafariでは正しくローディング検出できないようになってきたため、書き直したルーチン「SafariでURLローディング完了検出」を利用してください。

AppleScript名:SafariでURLをローディング
set aURL to "http://www.piyocast.com/as/"
–set aURL to ""

tell application "Safari"
  set d to count every window
  
if d = 0 then
    make new window
    
tell document 1
      set URL to aURL
    end tell
  else
    if aURL is not equal to "" then
      tell document 1
        set URL to aURL
      end tell
    end if
  end if
  
  
page_loaded(10) of me
  
  
set a to do JavaScript "document.title" in document 1
end tell

on page_loaded(timeout_value)
  repeat with i from 1 to (timeout_value * 10)
    tell application "Safari"
      if (do JavaScript "document.readyState" in document 1) is "complete" then
        return true
      else if i is the timeout_value then
        return false
      else
        delay 0.1
      end if
    end tell
  end repeat
  
return false
end page_loaded

★Click Here to Open This Script 

Posted in JavaScript URL | Tagged 10.11savvy 10.12savvy 10.13savvy Safari | 2 Comments

TextEditで色置換 v2

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:TextEditで色置換 v2
— Created 2018-01-09 by Takaaki Naganoya
— 2018 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use bPlus : script "BridgePlus" –https://www.macosxautomation.com/applescript/apps/BridgePlus.html

load framework

(*
set targColor to {65535, 10023, 4626}
set newColor to {19018, 0, 59109}
repTextEditColor(targColor, newColor) of me
*)

set targColor to {19018, 0, 59109}
set newColor to {65535, 10023, 4626}
repTextEditColor(targColor, newColor) of me

on repTextEditColor(targColor, newColor)
  set hitIndex to {}
  
  
tell application "TextEdit"
    tell text of front document
      set colList to color of every attribute run
    end tell
  end tell
  
  
set hitIndex to (current application’s SMSForder’s indexesOfItem:targColor inArray:(colList) inverting:false) as list
  
  
tell application "TextEdit"
    tell text of front document
      repeat with i in hitIndex
        ignoring application responses
          set color of attribute run (i + 1) to newColor –0 based index to 1 based index conversion
        end ignoring
      end repeat
    end tell
  end tell
end repTextEditColor

★Click Here to Open This Script 

Posted in Text | Tagged 10.11savvy 10.12savvy 10.13savvy TextEdit | Leave a comment

指定のテキストファイルをオープンする

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:指定のテキストファイルをオープンする
set a to choose file file of type {"public.plain-text"}
tell application "TextEdit"
  open a
end tell

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy TextEdit | Leave a comment

TextEditでmake時にデータを与えつつ新規ドキュメント作成

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:TextEditでmake時にデータを与えつつ新規ドキュメント作成
set a to "あいうえお"

tell application "TextEdit"
  make new document with properties {text:a}
end tell

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy TextEdit | Leave a comment

TextEditの文章のうち赤くマークされた行をカウントする

Posted on 2月 6, 2018 by Takaaki Naganoya

macOS標準装備のテキストエディットで編集中の文章のうち、赤くマークされた行をカウントするAppleScriptです。

RGB値で抽出してカウントします。30年前からやっている原始レベルの処理です。値が同じ箇所を抽出するだけならバカでもできます。

いま現在AppleScriptで実現しているのは、「赤っぽい色」の箇所を抽出する「カラードメイン処理」です。RGB値だと値が1つでも違っていたら別物として判定されてしまいますが、カラードメイン処理では「赤系統の色」を計算して判定できるものです。

→ TextEditの文章のうち赤っぽい色でマークされた箇所をピックアップする v2

→ TextEditの文章のうち赤っぽい色でマークされた行をカウントする v2

→ TextEdit本文色に応じて青っぽい色は男性の音声で、赤っぽい色は女性の音声で読み上げ

AppleScript名:TextEditの文章のうち赤くマークされた行をカウントする
set rNum to 0

tell application "TextEdit"
  tell text of document 1
    set pCount to (count paragraphs)
    
    
repeat with i from 1 to pCount
      set aCol to color of paragraph i
      
if aCol = {65535, 0, 0} then –{r, g, b}
        set rNum to rNum + 1
      end if
    end repeat
    
  end tell
end tell

return {pCount, rNum}

★Click Here to Open This Script 

Posted in Color list RTF | Tagged 10.11savvy 10.12savvy 10.13savvy TextEdit | 1 Comment

TextEditで文字数をカウントする

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:TextEditで文字数をカウントする
tell application "TextEdit"
  tell front document
    set a to text of it
  end tell
  
set tLen to length of a
  
display dialog (tLen as string) & "文字です" with title "この文章の文字数は…" buttons {"OK"} default button 1 with icon 1
end tell
–18058

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy TextEdit | Leave a comment

Post navigation

  • Older posts
  • Newer posts

電子書籍(PDF)をオンラインストアで販売中!

Google Search

Popular posts

  • 開発機としてM2 Mac miniが来たのでガチレビュー
  • macOS 15, Sequoia
  • Pages本執筆中に、2つの書類モード切り替えに気がついた
  • Numbersで選択範囲のセルの前後の空白を削除
  • メキシカンハットの描画
  • Pixelmator Pro v3.6.4でAppleScriptからの操作時の挙動に違和感が
  • AppleScriptによる並列処理
  • Safariで「プロファイル」機能を使うとAppleScriptの処理に影響
  • macOS 15でも変化したText to Speech環境
  • AppleScript入門③AppleScriptを使った「自動化」とは?
  • デフォルトインストールされたフォント名を取得するAppleScript
  • macOS 15 リモートApple Eventsにバグ?
  • 【続報】macOS 15.5で特定ファイル名パターンのfileをaliasにcastすると100%クラッシュするバグ
  • AppleScript入門① AppleScriptってなんだろう?
  • Script Debuggerの開発と販売が2025年に終了
  • macOS 14で変更になったOSバージョン取得APIの返り値
  • NSObjectのクラス名を取得 v2.1
  • 有害ではなくなっていたSpaces
  • macOS 15:スクリプトエディタのAppleScript用語辞書を確認できない
  • Xcode上のAppleScriptObjCのプログラムから、Xcodeのログ欄へのメッセージ出力を実行

Tags

10.11savvy (1101) 10.12savvy (1242) 10.13savvy (1391) 10.14savvy (587) 10.15savvy (438) 11.0savvy (283) 12.0savvy (212) 13.0savvy (194) 14.0savvy (147) 15.0savvy (135) CotEditor (66) Finder (51) iTunes (19) Keynote (119) NSAlert (61) NSArray (51) NSBitmapImageRep (20) NSBundle (20) NSButton (34) NSColor (53) NSDictionary (28) NSFileManager (23) NSFont (21) NSImage (41) NSJSONSerialization (21) NSMutableArray (63) NSMutableDictionary (22) NSPredicate (36) NSRunningApplication (56) NSScreen (30) NSScrollView (22) NSString (119) NSURL (98) NSURLRequest (23) NSUTF8StringEncoding (30) NSView (33) NSWorkspace (20) Numbers (76) Pages (55) Safari (44) Script Editor (27) WKUserContentController (21) WKUserScript (20) WKWebView (23) WKWebViewConfiguration (22)

カテゴリー

  • 2D Bin Packing
  • 3D
  • AirDrop
  • AirPlay
  • Animation
  • AppleScript Application on Xcode
  • Beginner
  • Benchmark
  • beta
  • Bluetooth
  • Books
  • boolean
  • bounds
  • Bug
  • Calendar
  • call by reference
  • check sum
  • Clipboard
  • Cocoa-AppleScript Applet
  • Code Sign
  • Color
  • Custom Class
  • date
  • dialog
  • diff
  • drive
  • Droplet
  • exif
  • file
  • File path
  • filter
  • folder
  • Font
  • Font
  • GAME
  • geolocation
  • GUI
  • GUI Scripting
  • Hex
  • History
  • How To
  • iCloud
  • Icon
  • Image
  • Input Method
  • Internet
  • iOS App
  • JavaScript
  • JSON
  • JXA
  • Keychain
  • Keychain
  • Language
  • Library
  • list
  • Locale
  • Localize
  • Machine Learning
  • Map
  • Markdown
  • Menu
  • Metadata
  • MIDI
  • MIME
  • Natural Language Processing
  • Network
  • news
  • Noification
  • Notarization
  • Number
  • Object control
  • OCR
  • OSA
  • parallel processing
  • PDF
  • Peripheral
  • process
  • PRODUCTS
  • QR Code
  • Raw AppleEvent Code
  • Record
  • rectangle
  • recursive call
  • regexp
  • Release
  • Remote Control
  • Require Control-Command-R to run
  • REST API
  • Review
  • RTF
  • Sandbox
  • Screen Saver
  • Script Libraries
  • sdef
  • search
  • Security
  • selection
  • shell script
  • Shortcuts Workflow
  • Sort
  • Sound
  • Spellchecker
  • Spotlight
  • SVG
  • System
  • Tag
  • Telephony
  • Text
  • Text to Speech
  • timezone
  • Tools
  • Update
  • URL
  • UTI
  • Web Contents Control
  • WiFi
  • XML
  • XML-RPC
  • イベント(Event)
  • 未分類

アーカイブ

  • 2025年6月
  • 2025年5月
  • 2025年4月
  • 2025年3月
  • 2025年2月
  • 2025年1月
  • 2024年12月
  • 2024年11月
  • 2024年10月
  • 2024年9月
  • 2024年8月
  • 2024年7月
  • 2024年6月
  • 2024年5月
  • 2024年4月
  • 2024年3月
  • 2024年2月
  • 2024年1月
  • 2023年12月
  • 2023年11月
  • 2023年10月
  • 2023年9月
  • 2023年8月
  • 2023年7月
  • 2023年6月
  • 2023年5月
  • 2023年4月
  • 2023年3月
  • 2023年2月
  • 2023年1月
  • 2022年12月
  • 2022年11月
  • 2022年10月
  • 2022年9月
  • 2022年8月
  • 2022年7月
  • 2022年6月
  • 2022年5月
  • 2022年4月
  • 2022年3月
  • 2022年2月
  • 2022年1月
  • 2021年12月
  • 2021年11月
  • 2021年10月
  • 2021年9月
  • 2021年8月
  • 2021年7月
  • 2021年6月
  • 2021年5月
  • 2021年4月
  • 2021年3月
  • 2021年2月
  • 2021年1月
  • 2020年12月
  • 2020年11月
  • 2020年10月
  • 2020年9月
  • 2020年8月
  • 2020年7月
  • 2020年6月
  • 2020年5月
  • 2020年4月
  • 2020年3月
  • 2020年2月
  • 2020年1月
  • 2019年12月
  • 2019年11月
  • 2019年10月
  • 2019年9月
  • 2019年8月
  • 2019年7月
  • 2019年6月
  • 2019年5月
  • 2019年4月
  • 2019年3月
  • 2019年2月
  • 2019年1月
  • 2018年12月
  • 2018年11月
  • 2018年10月
  • 2018年9月
  • 2018年8月
  • 2018年7月
  • 2018年6月
  • 2018年5月
  • 2018年4月
  • 2018年3月
  • 2018年2月

https://piyomarusoft.booth.pm/items/301502

メタ情報

  • ログイン
  • 投稿フィード
  • コメントフィード
  • WordPress.org

Forum Posts

  • 人気のトピック
  • 返信がないトピック

メタ情報

  • ログイン
  • 投稿フィード
  • コメントフィード
  • WordPress.org
Proudly powered by WordPress
Theme: Flint by Star Verte LLC