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

カテゴリー: 未分類

QuickTime Playerの最前面のムービーの現在表示中のコマをデスクトップにJPEG画像で保存

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:QuickTIme Playerの最前面のムービーの現在表示中のコマをデスクトップにJPEG画像で保存
— Created 2018-01-20 by Takaaki Naganoya
— 2018 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"
–http://piyocast.com/as/archives/5123

property NSUUID : a reference to current application’s NSUUID
property NSString : a reference to current application’s NSString
property NSImage : a reference to current application’s NSImage
property NSPasteboard : a reference to current application’s NSPasteboard
property NSJPEGFileType : a reference to current application’s NSJPEGFileType
property NSBitmapImageRep : a reference to current application’s NSBitmapImageRep

set the clipboard to "" –Clear Clipboard (=Pasteboard)

tell application "QuickTime Player"
  –No Document check
  
if (count every document) < 1 then
    display dialog "No Document…" with icon 2 buttons {"OK"} default button 1
    
return
  end if
  
  
–Audio Movie check  
  
if natural dimensions of front document = {0, 0} then
    display dialog "This is an audio file" with icon 2 buttons {"OK"} default button 1
    
return
  end if
end tell

repeat 100 times
  activate application "QuickTime Player"
  
  
tell application "System Events"
    tell process "QuickTime Player"
      click menu item 5 of menu 1 of menu bar item 4 of menu bar 1 –Edit > Copy
    end tell
  end tell
  
  
delay 0.1
  
  
set aRes to dataIsInClipboard for JPEG picture
  
if aRes = true then exit repeat
end repeat

if aRes = false then return

–クリップボードの内容をNSImageに
set aNSIMage to my getClipboardASImage()

–保存先とファイル名を求める
set targFol to POSIX path of (path to desktop)
set aUUID to NSUUID’s UUID()’s UUIDString() as text
set outPath to targFol & aUUID & ".jpg"

set aRes to saveNSImageAtPathAsJPG(aNSIMage, outPath, 1.0) of me

— クリップボードの内容をNSImageとして取り出して返す
on getClipboardASImage()
  set theNSPasteboard to NSPasteboard’s generalPasteboard()
  
set imageArray to theNSPasteboard’s readObjectsForClasses:({NSImage}) options:(missing value)
  
set targImage to imageArray’s objectAtIndex:0
  
return targImage
end getClipboardASImage

–NSImageを指定パスにJPEG形式で保存、qulityNumは0.0〜1.0。1.0は無圧縮
on saveNSImageAtPathAsJPG(anImage, outPath, qulityNum as real)
  set imageRep to anImage’s TIFFRepresentation()
  
set aRawimg to NSBitmapImageRep’s imageRepWithData:imageRep
  
set pathString to NSString’s stringWithString:outPath
  
set newPath to pathString’s stringByExpandingTildeInPath()
  
set myNewImageData to (aRawimg’s representationUsingType:(NSJPEGFileType) |properties|:{NSImageCompressionFactor:qulityNum})
  
return (myNewImageData’s writeToFile:newPath atomically:true) as boolean
end saveNSImageAtPathAsJPG

–http://ashplanning.blogspot.jp/2006/12/blog-post.html
on dataIsInClipboard for dataType
  return (clipboard info for dataType) is not {}
end dataIsInClipboard

★Click Here to Open This Script 

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

Numbersでセルのカラム幅を自動調整 v2

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:Numbersでセルのカラム幅を自動調整 v2
— Created 2018-1-11 by Takaaki Naganoya
— 2018 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
–http://piyocast.com/as/archives/5116

tell application "Numbers"
  tell front document
    tell sheet 1
      set tCount to count every table
      
if tCount = 0 then return
      
      
tell table 1
        set tableWidth to width
        
        
set cCount to count every column
        
set cWidth to width of every column
        
set aWidth to width –table width
        
        
set aveWidth to (aWidth – (first item of cWidth)) / (cCount – 1)
        
        
tell columns 2 thru cCount
          set width to aveWidth
        end tell
        
        
set wList to width of every column
      end tell
      
      
if tCount = 1 then return
      
      
set origCols to count every column of table 1
      
repeat with i from 2 to tCount
        if origCols is not equal to (count every column of table i) then
          display notification "Numbers: Column number is different in Table #" & (i as string)
          
return
        end if
      end repeat
      
      
repeat with i from 2 to tCount
        
        
tell table i
          set width to tableWidth
        end tell
        
        
set aCount to 1
        
        
tell table i
          repeat with ii from 1 to cCount
            tell column ii
              set width to (contents of item ii of wList)
            end tell
          end repeat
        end tell
        
      end repeat
    end tell
  end tell
end tell

★Click Here to Open This Script 

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

デスクトップ上のRetina解像度のスクリーンショット画像でICNS以外のものを検索

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:デスクトップ上のRetina解像度のスクリーンショット画像でICNS以外のものを検索
— Created 2017-09-23 by Takaaki Naganoya
— Modified 2017-12-01 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use mdLib : script "Metadata Lib" version "1.0.0" –https://www.macosxautomation.com/applescript/apps/Script_Libs.html#Metadata_Lib

set theFolder to path to desktop
set fRes to mdLib’s searchFolders:{theFolder} searchString:"kMDItemResolutionHeightDPI == %@ && kMDItemResolutionWidthDPI == %@ && kMDItemIsScreenCapture == %@ && NOT (kMDItemContentTypeTree contains %@)" searchArgs:{144, 144, true, "com.apple.icns"}
–> {"/Users/me/Desktop/FromDesktop/スクリーンショット 2015-12-18 13.02.14.png", "/Users/me/Desktop/FromDesktop/スクリーンショット 2015-08-14 18.08.41.png"}

★Click Here to Open This Script 

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

指定日時以降に作成されたファイルをSpotlight検索 v3

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:指定日時以降に作成されたファイルをSpotlight検索 v3
— Created 2017-09-21 by Takaaki Naganoya
— Modified 2017-09-22 by Shane Stanley
— 2017 Piyomaru Software
use AppleScript version "2.5"
use scripting additions
use framework "Foundation"
use mdLib : script "Metadata Lib" version "1.0.0"
–http://piyocast.com/as/archives/4841

property NSTimeZone : a reference to current application’s NSTimeZone
property NSCalendar : a reference to current application’s NSCalendar

set aDate to getDateInternationalYMDhms(2017, 10, 22, 0, 0, 0) of me
–>  (NSDate) 2017-09-21 14:02:00 +0000

set thePath to POSIX path of (path to desktop)
–>  "/Users/me/Desktop/"

set theFiles to mdLib’s searchFolders:{thePath} searchString:("kMDItemFSCreationDate >= %@") searchArgs:{aDate}
–> returns POSIX path list

on getDateInternationalYMDhms(aYear, aMonth, aDay, anHour, aMinute, aSecond)
  set theNSCalendar to NSCalendar’s currentCalendar()
  
set theDate to theNSCalendar’s dateWithEra:1 |year|:aYear |month|:aMonth |day|:aDay hour:anHour minute:aMinute |second|:aSecond nanosecond:0
  
return theDate
end getDateInternationalYMDhms

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a 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

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の最前面のドキュメントのテキストを取得する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

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

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
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

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
end tell

★Click Here to Open This Script 

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

CotEditor 3の選択範囲を書き換える

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:CotEditor 3の選択範囲を書き換える
tell application "CotEditor"
  tell document 1
    properties of selection
    
–> {range:{0, 4}, class:text selection, line range:{1, 1}, contents:"似ている"}
    
    
set contents of selection to "ほぼおなじ"
  end tell
end tell

★Click Here to Open This Script 

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

CotEditorでオープン中の最前面の書類の本文テキストを取得する

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:CotEditorでオープン中の最前面の書類の本文テキストを取得する
set aRes to getCotEditorText() of me

on getCotEditorText()
  tell application "CotEditor"
    if (count every document) = 0 then return false
    
tell front document
      set aText to contents
    end tell
  end tell
end getCotEditorText

★Click Here to Open This Script 

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

表示中のCotEditor書類の「次」のファイルを縦書きでオープン

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:表示中のCotEditor書類の「次」のファイルを縦書きでオープン
— Created 2017-12-15 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use bPlus : script "BridgePlus"
–http://piyocast.com/as/archives/5034

property |NSURL| : a reference to current application’s |NSURL|
property NSArray : a reference to current application’s NSArray
property NSString : a reference to current application’s NSString
property SMSForder : a reference to current application’s SMSForder
property NSPredicate : a reference to current application’s NSPredicate
property NSFileManager : a reference to current application’s NSFileManager
property NSMutableArray : a reference to current application’s NSMutableArray
property NSSortDescriptor : a reference to current application’s NSSortDescriptor
property NSURLIsPackageKey : a reference to current application’s NSURLIsPackageKey
property NSURLIsDirectoryKey : a reference to current application’s NSURLIsDirectoryKey
property NSDirectoryEnumerationSkipsHiddenFiles : a reference to current application’s NSDirectoryEnumerationSkipsHiddenFiles
property NSDirectoryEnumerationSkipsPackageDescendants : a reference to current application’s NSDirectoryEnumerationSkipsPackageDescendants
property NSDirectoryEnumerationSkipsSubdirectoryDescendants : a reference to current application’s NSDirectoryEnumerationSkipsSubdirectoryDescendants

load framework

tell application "CotEditor"
  set dCount to count every document
  
if dCount = 0 then return
  
  
tell front document
    set curPath to path
  end tell
  
  
tell window 1
    set aBounds to bounds
  end tell
end tell

set aPath to NSString’s stringWithString:curPath
set fileName to (aPath’s lastPathComponent()) –ファイル名
set pathExtension to aPath’s pathExtension() as string
set parentFol to (aPath’s stringByDeletingLastPathComponent()) as string —親フォルダ

–同じフォルダから同じ拡張子のファイルのファイル名を取得
set fList to my getFilesByIncludedStringInName:(pathExtension) fromDirectory:(parentFol) exceptPackages:(true)

–昇順ソート
set aArray to NSArray’s arrayWithArray:fList
set desc1 to NSSortDescriptor’s sortDescriptorWithKey:"self" ascending:true selector:"localizedCaseInsensitiveCompare:"
set bArray to aArray’s sortedArrayUsingDescriptors:{desc1}

–ファイル名検索
set aIndex to (SMSForder’s indexesOfItem:fileName inArray:bArray inverting:false) as list
if aIndex = {} then
  display notification "Error: File Not Found"
  
return
end if

set bIndex to (contents of first item of aIndex) + 1 + 1 –0 based to 1 based conversion & next one
set aLen to length of (bArray as list)
if bIndex > aLen then
  display notification "Error: Out of bounds"
  
return
end if

set newFile to contents of item bIndex of (bArray as list)
set newPath to parentFol & "/" & newFile

tell application "CotEditor"
  set oldDoc to front document
  
  
open (POSIX file newPath) as alias
  
tell window 1
    set bounds to aBounds
  end tell
  
  
close oldDoc without saving
end tell

makeWinVertical() of me –縦書き表示

–指定フォルダ内の指定文字列を含むファイル名のlistを抽出する
on getFilesByIncludedStringInName:(fileNameStr as string) fromDirectory:(sourceFolder) exceptPackages:(packageF as boolean)
  set fileManager to NSFileManager’s defaultManager()
  
set aURL to |NSURL|’s fileURLWithPath:sourceFolder
  
set theOptions to (NSDirectoryEnumerationSkipsPackageDescendants as integer) + (NSDirectoryEnumerationSkipsHiddenFiles as integer) + (NSDirectoryEnumerationSkipsSubdirectoryDescendants as integer)
  
set directoryContents to fileManager’s contentsOfDirectoryAtURL:aURL includingPropertiesForKeys:{} options:theOptions |error|:(missing value)
  
set findPredicates to NSPredicate’s predicateWithFormat_("lastPathComponent CONTAINS %@", fileNameStr)
  
set foundItemList to directoryContents’s filteredArrayUsingPredicate:findPredicates
  
  
–Remove Folders From found URL Array
  
set anArray to NSMutableArray’s alloc()’s init()
  
repeat with i in foundItemList
    set j to contents of i
    
set {theResult, isDirectory} to (j’s getResourceValue:(reference) forKey:(NSURLIsDirectoryKey) |error|:(missing value))
    
    
–Collect files
    
if (isDirectory as boolean = false) then
      (anArray’s addObject:j)
    else if (packageF = false) then
      –Allow Package files?
      
set {theResult, isPackage} to (j’s getResourceValue:(reference) forKey:(NSURLIsPackageKey) |error|:(missing value))
      
if (isPackage as boolean) = true then
        (anArray’s addObject:j)
      end if
    end if
    
  end repeat
  
  
return (anArray’s valueForKey:"lastPathComponent") as list
end getFilesByIncludedStringInName:fromDirectory:exceptPackages:

–Make CotEditor’s front window to Vertical display mode (Tategaki)
on makeWinVertical()
  activate application "CotEditor"
  
tell application "System Events"
    tell process "CotEditor"
      try
        click menu item "縦書きで表示" of menu 1 of menu bar item "フォーマット" of menu bar 1
      end try
    end tell
  end tell
end makeWinVertical

★Click Here to Open This Script 

Posted in GUI Scripting 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy CotEditor | Leave a comment

Post navigation

  • Older posts
  • Newer posts

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

Google Search

Popular posts

  • macOS 13, Ventura(継続更新)
  • アラートダイアログ上にWebViewで3Dコンテンツを表示(WebGL+three.js)v3
  • Xcode 14.2でAppleScript App Templateを復活させる
  • UI Browserがgithub上でソース公開され、オープンソースに
  • macOS 13 TTS Voice環境に変更
  • 2022年に書いた価値あるAppleScript
  • ChatGPTで文章のベクトル化(Embedding)
  • 新発売:AppleScriptからSiriを呼び出そう!
  • iWork 12.2がリリースされた
  • 従来と異なるmacOS 13の性格?
  • 新発売:CotEditor Scripting Book with AppleScript
  • macOS 13対応アップデート:AppleScript実践的テクニック集(1)GUI Scripting
  • macOS 13でNSNotFoundバグふたたび
  • ChatGPTでchatに対する応答文を取得
  • 新発売:iWork Scripting Book with AppleScript
  • Finderの隠し命令openVirtualLocationが発見される
  • macOS 13.1アップデートでスクリプトエディタの挙動がようやくまともに
  • あのコン過去ログビューワー(暫定版)
  • AppleScriptの数値変数で指数表示にならない最大値、最小値
  • バカスタム App選手権 入賞!

Tags

10.11savvy (1101) 10.12savvy (1242) 10.13savvy (1390) 10.14savvy (586) 10.15savvy (434) 11.0savvy (277) 12.0savvy (186) 13.0savvy (59) CotEditor (60) Finder (47) iTunes (19) Keynote (99) NSAlert (60) NSArray (51) NSBezierPath (18) NSBitmapImageRep (20) NSBundle (20) NSButton (34) NSColor (51) NSDictionary (27) NSFileManager (23) NSFont (18) NSImage (41) NSJSONSerialization (21) NSMutableArray (62) NSMutableDictionary (21) NSPredicate (36) NSRunningApplication (56) NSScreen (30) NSScrollView (22) NSString (117) NSURL (97) NSURLRequest (23) NSUTF8StringEncoding (30) NSView (33) NSWorkspace (20) Numbers (57) Pages (38) Safari (41) Script Editor (20) WKUserContentController (21) WKUserScript (20) WKUserScriptInjectionTimeAtDocumentEnd (18) WKWebView (23) WKWebViewConfiguration (22)

カテゴリー

  • 2D Bin Packing
  • 3D
  • AirDrop
  • AirPlay
  • Animation
  • AppleScript Application on Xcode
  • beta
  • Bluetooth
  • Books
  • boolean
  • bounds
  • Bug
  • Calendar
  • call by reference
  • Clipboard
  • Code Sign
  • Color
  • Custom Class
  • dialog
  • drive
  • 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
  • Machine Learning
  • Map
  • Markdown
  • Menu
  • Metadata
  • MIDI
  • MIME
  • Natural Language Processing
  • Network
  • news
  • Noification
  • Notarization
  • Number
  • Object control
  • OCR
  • OSA
  • PDF
  • Peripheral
  • 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)
  • 未分類

アーカイブ

  • 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