AppleScript名:指定画像をPNG形式で保存 |
— Created 2017-02-05 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "AppKit" set aFile to POSIX path of (choose file of type {"public.image"} with prompt "Select Image A") set aImage to current application’s NSImage’s alloc()’s initWithContentsOfFile:aFile set fRes to retUUIDfilePath(aFile, "png") of me set sRes to saveNSImageAtPathAsPNG(imgRes, fRes) of me on retUUIDfilePath(aPath, aEXT) set aUUIDstr to (current application’s NSUUID’s UUID()’s UUIDString()) as string set aPath to ((current application’s NSString’s stringWithString:aPath)’s stringByDeletingLastPathComponent()’s stringByAppendingPathComponent:aUUIDstr)’s stringByAppendingPathExtension:aEXT return aPath end retUUIDfilePath –NSImageを指定パスにPNG形式で保存 on saveNSImageAtPathAsPNG(anImage, outPath) set imageRep to anImage’s TIFFRepresentation() set aRawimg to current application’s NSBitmapImageRep’s imageRepWithData:imageRep set pathString to current application’s NSString’s stringWithString:outPath set newPath to pathString’s stringByExpandingTildeInPath() set myNewImageData to (aRawimg’s representationUsingType:(current application’s NSPNGFileType) |properties|:(missing value)) set aRes to (myNewImageData’s writeToFile:newPath atomically:true) as boolean return aRes –true/false end saveNSImageAtPathAsPNG |
カテゴリー: file
指定画像をJPG形式で保存
指定の画像をJPEG形式+指定圧縮率で保存するAppleScriptです。
現在は、これをさらに発展させて指定ファイルサイズになるまで圧縮率を順次変更して動的に圧縮率を変更して保存する、という処理に発展し、これは日常的に(SNSなどでアップロード可能なファイルサイズに制限があるサイトに画像掲載を行うさいに)利用しています。
AppleScript名:指定画像をJPG形式で保存 |
— Created 2017-02-05 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "AppKit" set aFile to POSIX path of (choose file of type {"public.image"} with prompt "Select Image A") set aImage to current application’s NSImage’s alloc()’s initWithContentsOfFile:aFile set fRes to retUUIDfilePath(aFile, "jpg") of me set sRes to saveNSImageAtPathAsJPG(aImage, fRes, 1.0) of me on retUUIDfilePath(aPath, aEXT) set aUUIDstr to (current application’s NSUUID’s UUID()’s UUIDString()) as string set aPath to ((current application’s NSString’s stringWithString:aPath)’s stringByDeletingLastPathComponent()’s stringByAppendingPathComponent:aUUIDstr)’s stringByAppendingPathExtension:aEXT return aPath end retUUIDfilePath –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 current application’s NSBitmapImageRep’s imageRepWithData:imageRep set pathString to current application’s NSString’s stringWithString:outPath set newPath to pathString’s stringByExpandingTildeInPath() set myNewImageData to (aRawimg’s representationUsingType:(current application’s NSJPEGFileType) |properties|:{NSImageCompressionFactor:qulityNum}) set aRes to (myNewImageData’s writeToFile:newPath atomically:true) as boolean return aRes –true/false end saveNSImageAtPathAsJPG |
指定画像をTIFF形式で保存
AppleScript名:指定画像をTIFF形式で保存 |
— Created 2017-02-05 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "AppKit" set aFile to POSIX path of (choose file of type {"public.image"} with prompt "Select Image A") set aImage to current application’s NSImage’s alloc()’s initWithContentsOfFile:aFile set fRes to retUUIDfilePath(aFile, "tif") of me set sRes to saveNSImageAtPathAsTIFF(imgRes, fRes) of me on retUUIDfilePath(aPath, aEXT) set aUUIDstr to (current application’s NSUUID’s UUID()’s UUIDString()) as string set aPath to ((current application’s NSString’s stringWithString:aPath)’s stringByDeletingLastPathComponent()’s stringByAppendingPathComponent:aUUIDstr)’s stringByAppendingPathExtension:aEXT return aPath end retUUIDfilePath –NSImageを指定パスにTIFF形式で保存 on saveNSImageAtPathAsTIFF(anImage, outPath) set imageRep to anImage’s TIFFRepresentation() set aRawimg to current application’s NSBitmapImageRep’s imageRepWithData:imageRep set pathString to current application’s NSString’s stringWithString:outPath set newPath to pathString’s stringByExpandingTildeInPath() set myNewImageData to (aRawimg’s representationUsingType:(current application’s NSTIFFFileType) |properties|:(missing value)) set aRes to (myNewImageData’s writeToFile:newPath atomically:true) as boolean return aRes –true/false end saveNSImageAtPathAsTIFF |
画像にステガノグラフィーで埋め込まれた文字列を取り出す
オープンソースのステガノグラフィーのプログラム「ISStego」(By Isaac Stevao Sena氏)を用いて、JPEG画像に埋め込んだ文字情報を取り出すAppleScriptです。
ISStegoは普通にObjective-Cで書かれたGUIベースのアプリケーションだったので、そのままではAppleScriptから呼び出せませんでした。
そこで、中身をそのままそっくり移し替えた新規フレームワーク「stegLib.framework」をでっちあげてビルドし、AppleScriptから呼び出してみました。
JPEG画像にUTF-8の文字情報(日本語文字列)を埋め込んで別のPNG画像に書き出し、書き出した画像からUTF-8の文字情報を取り出す実験を行ってみました。エンコードもデコードもうまく行っているようなので、うまく処理できていると思います。
ステガノグラフィーについて初めて聞いたのは20年ぐらい前のことと記憶していますが、こんなに手軽に使えるようになっていたとは驚きです。
▲Original Image
▲Information Embedded Image
AppleScript名:画像にステガノグラフィーで埋め込まれた文字列を取り出す |
— Created 2015-10-21 by Takaaki Naganoya — 2015 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "AppKit" use framework "stegLib" –https://github.com/isena/ISStego set aFile to POSIX path of (choose file of type {"public.png"}) set aFilePath to current application’s NSString’s stringWithString:aFile set aURL to current application’s |NSURL|’s fileURLWithPath:aFilePath set aImage to current application’s NSImage’s alloc()’s initWithContentsOfURL:aURL set aDecodedData to current application’s ISStegoDecoder’s alloc()’s init()’s decodeStegoImage:aImage |error|:(missing value) set resStr to (current application’s NSString’s alloc()’s initWithData:aDecodedData encoding:(current application’s NSUTF8StringEncoding)) as string –> "長野谷隆昌/ぴよまるソフトウェア/Piyomaru Software" |
画像にステガノグラフィーで情報を埋め込む
オープンソースのステガノグラフィー(steganography)のプログラム「ISStego」(By Isaac Stevao Sena氏)を用いて、JPEG画像に文字情報を埋め込むAppleScriptです。
ISStegoは普通にObjective-Cで書かれたGUIベースのアプリケーションだったので、そのままではAppleScriptから呼び出せませんでした。
そこで、中身をそのままそっくり移し替えた新規フレームワーク「stegLib.framework」をでっちあげてビルドし、AppleScriptから呼び出してみました。
JPEG画像にUTF-8の文字情報(日本語文字列)を埋め込んで別のPNG画像に書き出し、書き出した画像からUTF-8の文字情報を取り出す実験を行ってみました。エンコードもデコードもうまく行っているようなので、うまく処理できていると思います。
ステガノグラフィー(steganography)について初めて聞いたのは20年ぐらい前のことと記憶していますが、こんなに手軽に使えるようになっていたとは驚きです。
Twitterにプログラムを投稿するのに、(140文字制限を回避するため)文字を画像化して投稿しているのを見て、「そこまでやるなら、画像にプログラムの文字データを埋め込めばいいのに」と思い、「ステガノグラフィーで埋め込めばいいんじゃないか?」ということで、埋め込めるようになったのですが、肝心のTwitterクライアントから画像をダウンロードする手段がなかったのがダメダメでした(Webブラウザ経由ならOKです)。
▲Original Image
▲Information Embedded Image
AppleScript名:画像にステガノグラフィーで情報を埋め込む |
— Created 2015-10-21 by Takaaki Naganoya — 2015 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "AppKit" use framework "stegLib" –https://github.com/isena/ISStego set aFile to POSIX path of (choose file of type {"public.jpeg"}) set encString to "長野谷隆昌/ぴよまるソフトウェア/Piyomaru Software" set aFilePath to current application’s NSString’s stringWithString:aFile set aExt to "png" set newPath to aFilePath’s stringByDeletingPathExtension() set newPath2 to newPath’s stringByAppendingString:"_stego" set newPath3 to newPath2’s stringByAppendingPathExtension:aExt set aURL to current application’s |NSURL|’s fileURLWithPath:aFilePath set aImage to current application’s NSImage’s alloc()’s initWithContentsOfURL:aURL set strData to current application’s NSString’s stringWithString:encString set aEncimage to current application’s ISStegoEncoder’s alloc()’s init()’s stegoImageForImage:aImage |data|:strData |error|:(missing value) my saveImageRepAtPathAsPNG(aEncimage, newPath3) –画像を指定パスにPNG形式で保存 on saveImageRepAtPathAsPNG(anImage, outPath) set imageRep to anImage’s TIFFRepresentation() set aRawimg to current application’s NSBitmapImageRep’s imageRepWithData:imageRep set pathString to current application’s NSString’s stringWithString:outPath set newPath to pathString’s stringByExpandingTildeInPath() set myNewImageData to (aRawimg’s representationUsingType:(current application’s NSPNGFileType) |properties|:(missing value)) return (myNewImageData’s writeToFile:newPath atomically:true) as boolean end saveImageRepAtPathAsPNG |
拡張子でUTIを指定しつつchoose file of type
choose fileコマンドを拡張して、選択対象をUTIではなくファイル拡張子で指定できるようにしたAppleScriptです。
もともと、Classic Mac OSの時代からファイルのタイプを指し示す識別子としてFile Type(”PICT”とか”MooV”とか)が存在していましたが、OS X 10.6あたりで廃止になり、ウヤムヤのまま部分的に延命してきたものの、macOS 10.13でファイルシステムにAPFSを採用(File Typeなどの情報がFile System上に存在しない)したことにより、完全に使用不能になりました。
ファイルの区別に利用してきた情報としては、File type以外にも、
拡張子(複数の書き方をすることがある。.jpgとか.jpegとか)
ファイルkind(ローカライズされている)
type identifier(UTIのこと)
が存在しています。
「すべての画像」「プレーンテキスト全般」といったざっくりとした指定が可能なUTIは、AppleScript側にあまり機能が解放されておらず、あまり利用できていなかったのですが、macOS 10.10でCocoaの機能が利用できるようになってからはUTIの利用もすすんできました。
ただ、それなりに調べる作業も必要だったり、ツールを併用する必要もあったりするので、ファイル拡張子からUTIをScriptで調べて指定できたほうが便利な場合もあるのでは? と考え、このようなルーチン(+命令拡張)を書いてみたものです。
AppleScript名:拡張子でUTIを指定しつつchoose file of type |
— Created 2018-1-20 by Takaaki Naganoya — 2018 Piyomaru Software use AppleScript version "2.4" use framework "Foundation" use scripting additions use BridgePlus : script "BridgePlus" –https://www.macosxautomation.com/applescript/apps/BridgePlus.html set aFile to choose file of type {"jpg", "png"} with prompt "This is a message" set bFile to choose file of type {"scpt", "scptd"} with prompt "With default locaion" default location (path to desktop) on choose file of type extList with prompt aMes as string : "" default location aLoc : missing value set utiList to {} repeat with i in extList set the end of utiList to retFileFormatUTI(i) of me end repeat if aLoc = missing value then continue choose file of type utiList with prompt aMes else continue choose file of type utiList with prompt aMes default location aLoc end if end choose file on retFileFormatUTI(aExt as string) load framework return (current application’s SMSForder’s UTIForExtension:aExt) as string end retFileFormatUTI |
指定UTIでUTIを入れたリストをフィルタリング
AppleScript名:指定UTIでUTIを入れたリストをフィルタリング |
— Created 2017-11-03 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" property NSPredicate : a reference to current application’s NSPredicate property NSArray : a reference to current application’s NSArray set aList to {"public.jpeg", "com.compuserve.gif", "public.svg-image", "public.plain-text", "com.apple.iwork.keynote.key", "com.apple.iwork.pages.pages", "com.apple.iwork.numbers.numbers", "com.microsoft.word.doc", "com.microsoft.excel.xls", "com.microsoft.powerpoint.ppt", "com.apple.mail.email", "com.apple.applescript.script", "com.apple.applescript.text", "public.html", "com.apple.property-list", "public.zip-archive", "public.au-audio", "com.apple.m4a-audio", "com.apple.m4v-video"} set aRes to filterUTIList(aList, "public.text") –> {"public.plain-text", "com.apple.applescript.script", "com.apple.applescript.text", "public.html"} set bRes to filterUTIList(aList, "public.image") –> {"public.jpeg", "com.compuserve.gif", "public.svg-image"} set cRes to filterUTIList(aList, "public.audiovisual-content") –> {"public.au-audio", "com.apple.m4a-audio", "com.apple.m4v-video"} on filterUTIList(aUTIList, aUTIstr) set anArray to NSArray’s arrayWithArray:aUTIList set aPred to NSPredicate’s predicateWithFormat_("SELF UTI-CONFORMS-TO %@", aUTIstr) set bRes to (anArray’s filteredArrayUsingPredicate:aPred) as list return bRes end filterUTIList |
指定拡張子のUTI文字列を取得する
AppleScript名:指定拡張子のUTI文字列を取得する |
— Created 2016-10-24 by Takaaki Naganoya — Modified 2016-10-25 by Shane Stanley — 2016 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "AVFoundation" use BridgePlus : script "BridgePlus" –https://www.macosxautomation.com/applescript/apps/BridgePlus.html set aRes to retFileFormatUTI("mov") of me –> "com.apple.quicktime-movie" set aRes to retFileFormatUTI("mp4") of me –> "public.mpeg-4" set aRes to retFileFormatUTI("m4v") of me –> "com.apple.m4v-video" set aRes to retFileFormatUTI("m4a") of me –> "com.apple.m4a-audio" set aRes to retFileFormatUTI("3gp") of me –> "public.3gpp" set aRes to retFileFormatUTI("3gp2") of me –> "public.3gpp2" set aRes to retFileFormatUTI("caf") of me –> "com.apple.coreaudio-format" set aRes to retFileFormatUTI("wav") of me –> "com.microsoft.waveform-audio" set aRes to retFileFormatUTI("aif") of me –> "public.aifc-audio" set aRes to retFileFormatUTI("aifc") of me –> "public.aifc-audio" set aRes to retFileFormatUTI("amr") of me –> "org.3gpp.adaptive-multi-rate-audio" set aRes to retFileFormatUTI("mp3") of me –> "public.mp3" set aRes to retFileFormatUTI("au") of me –> "public.au-audio" set aRes to retFileFormatUTI("ac3") of me –> "public.ac3-audio" on retFileFormatUTI(aExt as string) load framework return (current application’s SMSForder’s UTIForExtension:aExt) as list of string or string end retFileFormatUTI |
指定ファイルのUTI情報を取得
AppleScript名:指定ファイルのUTI情報を取得 |
— Created 2017-10-25 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "MagicKit" –https://github.com/aidansteele/magickit set aFile to POSIX path of (choose file) set aRes to (current application’s GEMagicKit’s magicForFileAtPath:aFile) set aaRes to aRes’s |description|() as string –> "ISO Media, MPEG v4 system, version 2" set aMime to (aRes’s mimeType()) as string –> "video/mp4; charset=binary" set utiList to (aRes’s uniformTypeHierarchy()) as list –> {"com.apple.quicktime-movie", "public.movie", "public.audiovisual-content", "public.data", "public.content", "public.item"} set aDesc to (aRes’s |description|()) as string –> "ISO Media, Apple QuickTime movie" |
指定ファイルからカスタムアイコンを削除する
AppleScript名:指定ファイルからカスタムアイコンを削除する |
— Created 2015-10-19 by Takaaki Naganoya — 2015 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "AppKit" set aFile to POSIX path of (choose file with prompt "Choose Target File") –設定対象のファイル set aSW to current application’s NSWorkspace’s sharedWorkspace() aSW’s setIcon:(missing value) forFile:aFile options:0 |
指定ファイルに指定アイコン画像をつける
AppleScript名:指定ファイルに指定アイコン画像をつける |
— Created 2015-10-19 by Takaaki Naganoya — 2015 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "AppKit" set aPath to POSIX path of (choose file of type {"com.apple.icns", "public.tiff"} with prompt "Choose Icon File") –アイコンファイル set aFile to POSIX path of (choose file with prompt "Choose Target File") –設定対象のファイル set aURL to current application’s |NSURL|’s fileURLWithPath:aPath set aImage to current application’s NSImage’s alloc()’s initWithContentsOfURL:aURL set aSW to current application’s NSWorkspace’s sharedWorkspace() aSW’s setIcon:aImage forFile:aFile options:0 |
指定ファイルのxattrの削除(ダウンロードしたファイルが開けないときに)
AppleScript名:指定ファイルのxattrの削除(ダウンロードしたファイルが開けないときに) |
use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "XAttribute" –https://github.com/rylio/OTMXAttribute set dlFullPath to POSIX path of (choose file) set xRes to removeXAttrFromFile(dlFullPath, "com.apple.quarantine") on removeXAttrFromFile(aFile, anXattr) –Get Xattr String set anAttribute to (current application’s OTMXAttribute’s stringAttributeAtPath:aFile |name|:anXattr |error|:(missing value)) if anAttribute = missing value then return true –There is no use to remove xattr –Remove Xattr set xRes to (current application’s OTMXAttribute’s removeAttributeAtPath:aFile |name|:anXattr |error|:(missing value)) if xRes = missing value then return false return (xRes as boolean) end removeXAttrFromFile |
2D ListをCSVに v3(サニタイズ処理つき)
AppleScript名:2D ListをCSVに v3(サニタイズ処理つき) |
— Created 2015-10-01 by Takaaki Naganoya — 2015 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set aNewFile to choose file name set dataList to {{"0010", "ひよこタオルギフト", "200", "手に取ったとき、\"使うとき\"、ちょっと楽しくてかわいいひよこのタオル。", "●サイズ/H200㎜×W200㎜●素材/ひよこ羽毛100%●重量/170g●内容/5枚入り"}, {"0020", "ひよこホイッスル", "250", "今までにないデザインの、ひよこ型のホイッスル。ぴよ〜音を音階で吹き分けます。", "●サイズ/H60㎜×W40㎜×D10㎜●素材/プラスチック ●色/ひよこ色●重量/10g●付属品/首かけロープ付き ●型番/PIYO1"}} saveAsCSV(dataList, aNewFile) of me –2D List to CSV file on saveAsCSV(aList, aPath) –set crlfChar to (ASCII character 13) & (ASCII character 10) set crlfChar to (string id 13) & (string id 10) set LF to (string id 10) set wholeText to "" repeat with i in aList set newLine to {} –Sanitize (Double Quote) repeat with ii in i set jj to ii as text set kk to repChar(jj, string id 34, (string id 34) & (string id 34)) of me –Escape Double Quote set the end of newLine to kk end repeat –Change Delimiter set aLineText to "" set curDelim to AppleScript’s text item delimiters set AppleScript’s text item delimiters to "\",\"" set aLineList to newLine as text set AppleScript’s text item delimiters to curDelim set aLineText to repChar(aLineList, return, "") of me –delete return set aLineText to repChar(aLineText, LF, "") of me –delete lf set wholeText to wholeText & "\"" & aLineText & "\"" & crlfChar –line terminator: CR+LF end repeat if (aPath as string) does not end with ".csv" then set bPath to aPath & ".csv" as Unicode text else set bPath to aPath as Unicode text end if write_to_file(wholeText, bPath, false) of me end saveAsCSV on write_to_file(this_data, target_file, append_data) tell current application try set the target_file to the target_file as text set the open_target_file to open for access file target_file with write permission if append_data is false then set eof of the open_target_file to 0 write this_data to the open_target_file starting at eof close access the open_target_file return true on error error_message try close access file target_file end try return error_message end try end tell end write_to_file on repChar(origText as text, targChar as text, repChar as text) set curDelim to AppleScript’s text item delimiters set AppleScript’s text item delimiters to targChar set tmpList to text items of origText set AppleScript’s text item delimiters to repChar set retText to tmpList as string set AppleScript’s text item delimiters to curDelim return retText end repChar |
CSVのParse 5(ASOC)
AppleScript名:CSVのParse 5(ASOC) |
–Created By Shane Stanley 2015/03/12 –Commented & Arranged By Takaaki Naganoya 2015/03/12 use scripting additions use framework "Foundation" set theString to "cust1,\"prod,1\",season 1, cust1,prod1,season2, cust2,prod1,event1,season1 cust2,prod3,event1,season 1" its makeListsFromCSV:theString commaIs:"," –> {{"cust1", "prod,1", "season 1"}, {"cust1", "prod1", "season2"}, {"cust2", "prod1", "event1", "season1"}, {"cust2", "prod3", "event1", "season 1"}} –CSV Parser ASOC ver (Translated from "ASObjCExtras.framework" Objective-C version) on makeListsFromCSV:theString commaIs:theComma set theRows to {} –最終的に出力するデータ(2D Listになる) set newLineCharSet to current application’s NSCharacterSet’s newlineCharacterSet() –改行キャラクタ set importantCharSet to current application’s NSMutableCharacterSet’s characterSetWithCharactersInString:("\"" & theComma) –カンマ importantCharSet’s formUnionWithCharacterSet:newLineCharSet set theNSScanner to current application’s NSScanner’s scannerWithString:theString theNSScanner’s setCharactersToBeSkipped:(missing value) –データ末尾を検出するまでループ repeat while (theNSScanner’s isAtEnd() as integer = 0) set insideQuotes to false set finishedRow to false set theColumns to {} set currentColumn to "" –すべての行を処理終了するまでループ(行内部の処理) repeat while (not finishedRow) set {theResult, tempString} to theNSScanner’s scanUpToCharactersFromSet:importantCharSet intoString:(reference) –log {"theResult", theResult, "tempString", tempString} if theResult as integer = 1 then set currentColumn to currentColumn & (tempString as text) –log {"currentColumn", currentColumn} –データ末尾検出 if theNSScanner’s isAtEnd() as integer = 1 then if currentColumn is not "" then set end of theColumns to currentColumn set finishedRow to true else –データ末尾ではない場合 set {theResult, tempString} to theNSScanner’s scanCharactersFromSet:newLineCharSet intoString:(reference) if theResult as integer = 1 then if insideQuotes then –ダブルクォート文字内の場合 set currentColumn to currentColumn & (tempString as text) else –ダブルクォート内ではない場合 if currentColumn is not "" then set end of theColumns to currentColumn set finishedRow to true end if else –行末文字が見つからない場合 set theResult to theNSScanner’s scanString:"\"" intoString:(missing value) if theResult as integer = 1 then –ダブルクォート文字が見つかった場合 if insideQuotes then –ダブルクォート文字内の場合 set theResult to theNSScanner’s scanString:"\"" intoString:(missing value) if theResult as integer = 1 then set currentColumn to currentColumn & "\"" else set insideQuotes to (not insideQuotes) end if else –ダブルクォート文字内ではない場合 set insideQuotes to (not insideQuotes) end if else –ダブルクォート文字が見つからなかった場合 set theResult to theNSScanner’s scanString:theComma intoString:(missing value) –カンマの検索 if theResult as integer = 1 then if insideQuotes then set currentColumn to currentColumn & theComma else set end of theColumns to currentColumn set currentColumn to "" theNSScanner’s scanCharactersFromSet:(current application’s NSCharacterSet’s whitespaceCharacterSet()) intoString:(missing value) end if end if end if end if end if end repeat if (count of theColumns) > 0 then set end of theRows to theColumns –行データ(1D List)をtheRowsに追加(2D List) end repeat return theRows end makeListsFromCSV:commaIs: |
CSVのParse 4a(ASOC)
AppleScript名:CSVのParse 4a(ASOC) |
— Created 2015-03-11 by Shane Stanley 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 someString to read (choose file of type {"public.comma-separated-values-text"}) set theData to current application’s SMSForder’s arrayFromCSV:someString commaIs:"," set theData to (current application’s SMSForder’s subarraysIn:theData paddedWith:"" |error|:(missing value)) as list –> {{"cust1", "prod,1", "season 1", ""}, {"cust1", "prod1", "season 2", ""}, {"cust2", "prod1", "event1", "season 1"}, {"cust2", "prod2", "event1", "season 2"}, {"cust2", "prod3", "event1", "season 1"}} |
ASOCでDict読み込みして、指定のMSの搭乗回数を取得する v2
AppleScript名:ASOCでDict読み込みして、指定のMSの搭乗回数を取得する v2 |
use AppleScript version "2.4" use scripting additions use framework "Foundation" set aName to "efsf.plist" set aFolName to "戦場の絆" set aRec to retDictFromPlist(aFolName, aName) of me set msL to msList of aRec set eList to filterRecListByLabel(msL, "msName CONTAINS ’近 ザクII(F2) 獲得済’") of me set aTimes to sortieTimes of first item of eList on retDictFromPlist(aFolName, aPlistName) set myAppSupDir to ((path to application support from user domain) as string) & aFolName & ":" tell application "System Events" –Finderでなくこちらを使ってみた tell folder myAppSupDir set aExit to exists of file aPlistName end tell end tell if aExit = false then return {} else set aPath to (POSIX path of myAppSupDir) & aPlistName set thePath to current application’s NSString’s stringWithString:aPath set thePath to thePath’s stringByExpandingTildeInPath() set theDict to current application’s NSDictionary’s dictionaryWithContentsOfFile:thePath return theDict as record end if end retDictFromPlist –リストに入れたレコードを、指定の属性ラベルの値で抽出 on filterRecListByLabel(aRecList as list, aPredicate as string) –ListからNSArrayへの型変換 set aArray to current application’s NSArray’s arrayWithArray:aRecList –抽出 set aPredicate to current application’s NSPredicate’s predicateWithFormat:aPredicate set filteredArray to aArray’s filteredArrayUsingPredicate:aPredicate –NSArrayからListに型変換して返す set bList to filteredArray as list return bList end filterRecListByLabel |
ASOCでDict書き込み_3(Bridge Plus)
AppleScript名:ASOCでDict書き込み_3(Bridge Plus) |
use AppleScript version "2.4" use framework "Foundation" use scripting additions use script "BridgePlus" — https://www.macosxautomation.com/applescript/apps/BridgePlus.html load framework — BridgePlus command to load set a1List to {"msName", "sortieTimes"} set b1List to {{"近 装甲強化型ジム 獲得済 COST: 200", 66}, {"遠 ジム・キャノン 獲得済 COST: 160", 43}, {"近 ザクII(F2) 獲得済 COST: 160", 42}, {"近 ジム・コマンド 獲得済 COST: 200", 32}, {"近 ジム(WD隊) 獲得済 COST: 160", 28}, {"近 陸戦型ガンダム 獲得済 COST: 220", 24}, {"近 ジム改 獲得済 COST: 240", 22}, {"遠 ガンタンク 獲得済 COST: 200", 22}, {"格 ジム(指揮官機) 獲得済 COST: 160", 20}, {"近 ジム 獲得済 COST: 120", 19}, {"遠 量産型ガンタンク 獲得済 COST: 160", 14}, {"格 陸戦型ジム 獲得済 COST: 120", 12}, {"格 ガンダム 獲得済 COST: 280", 11}, {"近 ジム・トレーナー 獲得済 COST: 120", 9}, {"射 ジム・スナイパーII(WD隊) 獲得済 COST: 220", 9}, {"射 陸戦型ガンダム(ジム頭) 獲得済 COST: 200", 7}, {"格 ガンダムEz8 獲得済 COST: 240", 6}, {"近 ジム・寒冷地仕様 獲得済 COST: 200", 6}, {"狙 ジム・スナイパーカスタム 獲得済 COST: 200", 6}, {"格 ジム・ストライカー 獲得済 COST: 180", 4}, {"格 ガンキャノン重装型 獲得済 COST: 160", 3}, {"近 アクア・ジム 獲得済 COST: 160", 2}, {"射 ガンキャノン 獲得済 COST: 200", 2}, {"近 ジム・コマンドライトアーマー 獲得済 COST: 160", 1}, {"格 ボールK型 獲得済 COST: 120", 0}, {"格 B.D.2号機 獲得済 COST: 260", 0}, {"格 プロトタイプガンダム 獲得済 COST: 280", 0}, {"近 パワード・ジム 獲得済 COST: 240", 0}, {"射 デザート・ジム 獲得済 COST: 160", 0}, {"遠 量産型ガンキャノン 獲得済 COST: 200", 0}} — BridgePlus uses SMSForder instead of SMSFord in ASOBjCExtras, but method is the same set aArray to current application’s SMSForder’s subarraysIn:b1List asDictionariesUsingLabels:a1List |error|:(missing value) set cRec to {msList:aArray, sortieDate:date string of (current date)} set aName to "efsf.plist" saveRecordToFolAsPlist(cRec, "戦場の絆", aName) of me on saveRecordToFolAsPlist(theRecord, folName, aName) set myAppSupDir to POSIX path of (path to application support from user domain) set folderURL to (current application’s class "NSURL"’s fileURLWithPath:myAppSupDir)’s URLByAppendingPathComponent:folName –do shell script(mkdir -p)のかわりに、指定ディレクトリまで作成 current application’s NSFileManager’s defaultManager()’s createDirectoryAtURL:folderURL withIntermediateDirectories:true attributes:(missing value) |error|:(missing value) set theDict to current application’s NSDictionary’s dictionaryWithDictionary:theRecord set aRes to theDict’s writeToURL:(folderURL’s URLByAppendingPathComponent:aName) atomically:true return aRes as boolean end saveRecordToFolAsPlist |
指定文字の花文字テキストを取得する(Retina対応)
指定の文字から花文字を作成するAppleScriptです。
「花文字」とは、任意の文字を組み合わせて指定の文字を作成するもので、「祝」という文字とスペースを組み合わせて、
祝 祝 祝祝祝祝祝祝 祝祝祝祝祝 祝 祝祝祝祝祝 祝 祝祝祝 祝祝 祝祝 祝祝祝祝祝祝 祝祝祝祝 祝祝祝 祝祝祝祝祝 祝 祝 祝 祝 祝 祝 祝祝 祝 祝 祝 祝祝 祝祝祝祝 祝 祝 祝
のように組み合わせた文字列のことです。
大昔の大型コンピュータの計算結果をプリンタに印刷する際に、ユーザーごとの計算結果の紙が混ざることを防ぐために、ヘッダーページを印刷するようになっていました。当時はまだアウトラインフォントから大きな文字を印刷する技術がなかったので、花文字のように文字を組み合わせて大きな文字を印刷するようなことを行なっていたようです(たぶん)。
類似の処理にこのようなものがあります。
→ Love
花文字はその名残りで、パソコンのメールなどで文字だけを使って何かを表現するような、原始的なアスキーアートの一種といえばよいのでしょうか。
かつては、花文字作成の専用アプリケーションが存在していました。AppleScript的には、そうしたアプリケーションに「このデータを作ってくれ」と依頼するのが本来のスタイルですが、アプリケーションがない場合には、原理的に別に難しいものではないので、自前で作ってしまえばいいわけです。
(1)指定サイズ、指定フォントで書式つきテキストを作成
(2)書式つきテキストをメモリー上に用意したブランク画像に描画
(3)メモリー上の画像のドットを順次読み取って、塗りつぶされている箇所といない箇所を順次検出
(4)塗りつぶし情報を文字列に表現。空白ドットは空白文字で、描画ドットは指定文字で
(5)文字列を出力
という処理を行なっています。描画時のフォント種別の指定や、結果をCotEditorに出力するあたりは「オマケ」です。
この程度の処理であれば、JEdit Ωやmi、OS標準装備のテキストエディットなどさまざまな(AppleScript対応の)エディタにオープンさせられます(Mac用のテキストエディタでAppleScript非対応というものがあれば、何の迷いもなくゴミ箱行きです)。
AppleScript名:指定文字の花文字テキストを取得する(Retina対応) |
— Created 2017-12-12 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "AppKit" property NSFont : a reference to current application’s NSFont property NSUUID : a reference to current application’s NSUUID property NSColor : a reference to current application’s NSColor property NSArray : a reference to current application’s NSArray property NSString : a reference to current application’s NSString property NSImage : a reference to current application’s NSImage property NSPredicate : a reference to current application’s NSPredicate property NSDictionary : a reference to current application’s NSDictionary property NSBezierPath : a reference to current application’s NSBezierPath property NSColorSpace : a reference to current application’s NSColorSpace property NSPNGFileType : a reference to current application’s NSPNGFileType property NSFontManager : a reference to current application’s NSFontManager property NSBitmapImageRep : a reference to current application’s NSBitmapImageRep property NSMutableDictionary : a reference to current application’s NSMutableDictionary property NSFontAttributeName : a reference to current application’s NSFontAttributeName property NSKernAttributeName : a reference to current application’s NSKernAttributeName property NSMutableParagraphStyle : a reference to current application’s NSMutableParagraphStyle property NSLigatureAttributeName : a reference to current application’s NSLigatureAttributeName property NSMutableAttributedString : a reference to current application’s NSMutableAttributedString property NSUnderlineStyleAttributeName : a reference to current application’s NSUnderlineStyleAttributeName property NSParagraphStyleAttributeName : a reference to current application’s NSParagraphStyleAttributeName property NSForegroundColorAttributeName : a reference to current application’s NSForegroundColorAttributeName set aString to "あ" set hanaSize to 24 set thisFont to selectAFont(aString) of me if thisFont = false then return –Cancel –花文字文字列を作成 set fRes to getHanamojiStr(hanaSize, thisFont, aString, 0.7, true) of me makeNewDocument given parameter:fRes –花文字文字列を計算して返す on getHanamojiStr(aFontSize as real, aFontName as string, aString as string, aThread as real, incFontName as boolean) if length of aString is not equal to 1 then return false –指定文字コードが指定フォント中に存在するかチェック set fRes to retGlyphsInFont(aFontName, id of aString) of me if fRes = false then return false set aThreadShould to 768 * aThread if (chkMultiByteChar(aString) of me) = false then set spaceChar to string id 12288 –全角スペース(UTF-16) else set spaceChar to string id 32 –半角スペース end if set fillColor to NSColor’s whiteColor –塗り色 set bString to aString & " " –処理内容の帳尻合わせ(そのままだと右端が欠けるのでスペースを入れた) set anAssrStr to makeRTFfromParameters(bString, aFontName, aFontSize, -2, (aFontSize * 1.2)) of me set aSize to anAssrStr’s |size|() if class of aSize = record then set attrStrWidth to width of aSize set attrStrHeight to height of aSize else if class of aSize = list then –macOS 10.13.xのバグ回避 copy aSize to {attrStrWidth, attrStrHeight} end if set {xPos, yPos} to {0, 0} set tmpImg1 to makeImageWithFilledColor(attrStrWidth, attrStrHeight, fillColor) of me set tmpImg2 to drawAttributedStringsOnImage(tmpImg1, anAssrStr, xPos, yPos) of me set aRawimg to NSBitmapImageRep’s imageRepWithData:(tmpImg2’s TIFFRepresentation()) –画像から順次指定座標の色データを拾って花文字listに反映 set strList to {} repeat with y from 1 to attrStrHeight – 1 set strListX to {} repeat with x from 0 to attrStrWidth – 1 set tmpCol to getColorFromRawImage(aRawimg, x, y) of me if tmpCol is not equal to false then if tmpCol is not equal to {255, 255, 255} then copy tmpCol to {tmpR, tmpG, tmpB} if (tmpR + tmpG + tmpB) < aThreadShould then set the end of strListX to aString else set the end of strListX to spaceChar end if else set the end of strListX to spaceChar end if end if end repeat set the end of strList to strListX end repeat –2D List→Text set aRes to list2dToStringByUsingDelimiters(strList, "", return) of me if incFontName = true then set fName to getDisplayedNameOfFont(aFontName) of me set aRes to "■" & fName & return & return & aRes end if return aRes end getHanamojiStr –指定Raw画像中の指定座標のピクセルの色をRGBで取り出す on getColorFromRawImage(aRawimg, x as real, y as real) set aRatio to getImageRatio() of me –Retina Display対応 set origColor to (aRawimg’s colorAtX:(x * aRatio) y:(y * aRatio)) set srgbColSpace to NSColorSpace’s deviceRGBColorSpace if srgbColSpace = missing value then return false set aColor to (origColor’s colorUsingColorSpace:srgbColSpace) set aRed to (aColor’s redComponent()) * 255 set aGreen to (aColor’s greenComponent()) * 255 set aBlue to (aColor’s blueComponent()) * 255 return {aRed as integer, aGreen as integer, aBlue as integer} end getColorFromRawImage –画像のうえに指定のスタイル付きテキストを描画して画像を返す on drawAttributedStringsOnImage(anImage, anAssrStr, xPos as real, yPos as real) anImage’s lockFocus() anAssrStr’s drawAtPoint:(current application’s NSMakePoint(xPos, yPos)) anImage’s unlockFocus() return anImage end drawAttributedStringsOnImage –書式つきテキストを組み立てる on makeRTFfromParameters(aStr as string, fontName as string, aFontSize as real, aKerning as real, aLineSpacing as real) set aVal1 to NSFont’s fontWithName:fontName |size|:aFontSize set aKey1 to (NSFontAttributeName) set aVal2 to NSColor’s blackColor() set aKey2 to (NSForegroundColorAttributeName) set aVal3 to aKerning set akey3 to (NSKernAttributeName) set aVal4 to 0 set akey4 to (NSUnderlineStyleAttributeName) set aVal5 to 2 –all ligature ON set akey5 to (NSLigatureAttributeName) set aParagraphStyle to NSMutableParagraphStyle’s alloc()’s init() aParagraphStyle’s setMinimumLineHeight:(aLineSpacing) aParagraphStyle’s setMaximumLineHeight:(aLineSpacing) set akey7 to (NSParagraphStyleAttributeName) set keyList to {aKey1, aKey2, akey3, akey4, akey5, akey7} set valList to {aVal1, aVal2, aVal3, aVal4, aVal5, aParagraphStyle} set attrsDictionary to NSMutableDictionary’s dictionaryWithObjects:valList forKeys:keyList set attrStr to NSMutableAttributedString’s alloc()’s initWithString:aStr attributes:attrsDictionary return attrStr end makeRTFfromParameters –指定サイズの画像を作成し、背景を指定色で塗る on makeImageWithFilledColor(aWidth as real, aHeight as real, fillColor) set anImage to NSImage’s alloc()’s initWithSize:(current application’s NSMakeSize(aWidth, aHeight)) set aRatio to getImageRatio() of me –Retina Display対応 anImage’s lockFocus() set theRect to {{x:0, y:0}, {width:aWidth * aRatio, height:aHeight * aRatio}} set theNSBezierPath to NSBezierPath’s bezierPath theNSBezierPath’s appendBezierPathWithRect:theRect fillColor’s |set|() theNSBezierPath’s fill() anImage’s unlockFocus() return anImage end makeImageWithFilledColor –2D Listをアイテム間および行間のデリミタを個別に指定してテキスト変換 on list2dToStringByUsingDelimiters(aList as list, itemDelimiter, lineDelimiter) set outList to {} repeat with i in aList set aStr to listToStringUsingTextItemDelimiter(i, itemDelimiter) of me set the end of outList to aStr end repeat set bStr to listToStringUsingTextItemDelimiter(outList, lineDelimiter) of me return bStr end list2dToStringByUsingDelimiters on listToStringUsingTextItemDelimiter(sourceList as list, textItemDelimiter) set CocoaArray to NSArray’s arrayWithArray:sourceList set CocoaString to CocoaArray’s componentsJoinedByString:textItemDelimiter return (CocoaString as string) end listToStringUsingTextItemDelimiter –ユーザー環境にインストールされているすべてのフォントのPostScript名とグリフ数を返す on getEveryFontPSNameANdGlyphsNum(aStr) set aFontList to NSFontManager’s sharedFontManager()’s availableFonts() set thePred to NSPredicate’s predicateWithFormat:"NOT SELF BEGINSWITH ’.’" set aFontList to (aFontList’s filteredArrayUsingPredicate:thePred) as list set aList to {} repeat with i in aFontList set aName to contents of i set aNum to countNumberOfGlyphsInFont(aName) of me set dName to getDisplayedNameOfFont(aName) of me set fRes to retGlyphsInFont(aName, id of aStr) of me if fRes = true then set the end of aList to {fontName:aName, fontNum:aNum, dispName:dName} end if end repeat return aList end getEveryFontPSNameANdGlyphsNum –指定Postscript名称のフォントに定義されている文字数を数えて返す on countNumberOfGlyphsInFont(fontName as string) set aFont to NSFont’s fontWithName:fontName |size|:9.0 if aFont = missing value then return false set aProp to aFont’s numberOfGlyphs() return aProp as number end countNumberOfGlyphsInFont –フォントのPostScript NameからDisplayed Nameを取得 on getDisplayedNameOfFont(aName as string) set aFont to NSFont’s fontWithName:aName |size|:9.0 set aDispName to (aFont’s displayName()) as string return aDispName end getDisplayedNameOfFont –全角文字が存在するか on chkMultiByteChar(checkString as string) set aStr to NSString’s stringWithString:checkString set aRes to aStr’s canBeConvertedToEncoding:(current application’s NSASCIIStringEncoding) return (aRes as boolean) end chkMultiByteChar –指定名称のフォントに指定の文字コードが含まれているかチェック on retGlyphsInFont(fontName as string, strCode as integer) set aFont to NSFont’s fontWithName:fontName |size|:24.0 if aFont = missing value then return false set aSet to aFont’s coveredCharacterSet() set aRes to (aSet’s characterIsMember:strCode) as boolean return aRes as list of string or string –as anything end retGlyphsInFont on selectAFont(aString) set fRes to getEveryFontPSNameANdGlyphsNum(aString) of me set theArray to NSArray’s arrayWithArray:fRes set thePred to NSPredicate’s predicateWithFormat:"fontNum > 10000" set bArray to ((theArray’s filteredArrayUsingPredicate:thePred)’s valueForKeyPath:"dispName") as list set thisFont to choose from list bArray return thisFont end selectAFont –Retina Display対応ルーチン on getImageRatio() set retinaF to detectRetinaDisplay() of me if retinaF = true then return 2.0 as real else return 1.0 as real end if end getImageRatio on detectRetinaDisplay() set dispList to current application’s NSScreen’s screens() set retinaF to false repeat with i in dispList set j to contents of i set aDepth to j’s backingScaleFactor() if aDepth > 1.0 then set retinaF to true end if end repeat return retinaF end detectRetinaDisplay on makeNewDocument given parameter:aStr tell application id "com.coteditor.CotEditor" activate set newDoc to make new document tell newDoc set contents to aStr end tell end tell end makeNewDocument |
指定フォルダ内のラベル(Yellow, Red, Orange)のファイル一覧を取得
AppleScript名:指定フォルダ内のラベル(Yellow, Red, Orange)のファイル一覧を取得 |
— Created 2017-12-05 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 aLabelList to {5, 6, 7} –Yellow, Red, Orange –0: No Label, 1: Gray, 2: Green, 3: Purple, 4: Blue, 5: Yellow, 6: Red, 7: Orange set thePath to POSIX path of (path to desktop) set aRes to spotlightFindByLabels(aLabelList, thePath) of me –> list of POSIX path on spotlightFindByLabels(aLabelList as list, thePath as string) set aList to makeRepeatinglList(length of aLabelList, "kMDItemFSLabel == %@") set aStr to retStrFromArrayWithDelimiter(aList, " OR ") of me set fRes to mdLib’s searchFolders:{thePath} searchString:aStr searchArgs:aLabelList return fRes end spotlightFindByLabels –リストを指定デリミタをはさんでテキスト化 on retStrFromArrayWithDelimiter(aList as list, aDelim as string) set anArray to current application’s NSArray’s arrayWithArray:aList return (anArray’s componentsJoinedByString:aDelim) as string end retStrFromArrayWithDelimiter –指定回数、指定アイテムを連結したリストを作成 on makeRepeatinglList(hitNum as integer, hitItem as string) set outList to {} repeat hitNum times set the end of outList to hitItem end repeat return outList end makeRepeatinglList |
表示中のCotEditor書類と同じフォルダでラベルがついているものから選択して表示
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" use mdLib : script "Metadata Lib" version "1.0.0" property NSURLIsDirectoryKey : a reference to current application’s NSURLIsDirectoryKey property NSDirectoryEnumerationSkipsHiddenFiles : a reference to current application’s NSDirectoryEnumerationSkipsHiddenFiles property NSPredicate : a reference to current application’s NSPredicate property NSMutableArray : a reference to current application’s NSMutableArray property NSDirectoryEnumerationSkipsPackageDescendants : a reference to current application’s NSDirectoryEnumerationSkipsPackageDescendants property NSFileManager : a reference to current application’s NSFileManager property |NSURL| : a reference to current application’s |NSURL| property NSDirectoryEnumerationSkipsSubdirectoryDescendants : a reference to current application’s NSDirectoryEnumerationSkipsSubdirectoryDescendants property NSArray : a reference to current application’s NSArray property NSSortDescriptor : a reference to current application’s NSSortDescriptor property SMSForder : a reference to current application’s SMSForder 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 current application’s 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 fList to spotlightFindByLabels({1, 2, 3, 4, 5, 6, 7}, parentFol) of me –昇順ソート 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 cList to bArray as list set selRes to choose from list cList if selRes = false then return –Cancel set newPath to contents of first item of selRes 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 –縦書き表示 –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 on retFileFormatUTI(aExt as string) if aExt begins with "." then set aExt to text 2 thru -1 of aExt return (current application’s SMSForder’s UTIForExtension:aExt) end retFileFormatUTI on spotlightFindByLabels(aLabelList as list, thePath as string) set aList to makeRepeatinglList(length of aLabelList, "kMDItemFSLabel == %@") set aStr to retStrFromArrayWithDelimiter(aList, " OR ") of me set fRes to mdLib’s searchFolders:{thePath} searchString:aStr searchArgs:aLabelList return fRes end spotlightFindByLabels –リストを指定デリミタをはさんでテキスト化 on retStrFromArrayWithDelimiter(aList as list, aDelim as string) set anArray to current application’s NSArray’s arrayWithArray:aList return (anArray’s componentsJoinedByString:aDelim) as string end retStrFromArrayWithDelimiter –指定回数、指定アイテムを連結したリストを作成 on makeRepeatinglList(hitNum as integer, hitItem as string) set outList to {} repeat hitNum times set the end of outList to hitItem end repeat return outList end makeRepeatinglList |