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

月: 2019年5月

Photoshop CCでファイルをオープン

Posted on 5月 29, 2019 by Takaaki Naganoya

Photoshop CCで画像ファイル/PDFをオープンするAppleScriptです。

作成と動作確認はmacOS 10.14.5+Photoshop CC2019で行っています。一般的な画像ファイルのオープンはこちら。

Adobeのアプリケーションの操作を行っていると、5分に1回ぐらい首をひねる瞬間がやってきますが、疑問に思っても無駄なので、各種操作はサブルーチンに追い出して、直接Adobeアプリケーションの相手をしないほうが精神衛生上よいと思われます(contentsという超重要な予約語がコンフリクトしているのでオブジェクトを取り出してループするときに途方に暮れるとか、アプリケーションによってはオブジェクトの座標情報の順序がおかしいとかいろいろ)。

その中でもとびきりおかしいのが、この、Photoshopでのファイルオープン時のファイルパスの取り扱いです。

結局このおかしな書き方でしかオープンしてくれない(aliasを直接openできない謎仕様)という状況で、ここで疑問が生まれると、ふたたびAdobeのアプリケーションのおかしな仕様をひととおり体験することになるのです。

# 後から気づきましたが、Photoshopのopen命令は返り値がないですね、、、、

AppleScript名:Photoshop CCで画像ファイルをオープンする
set a to choose file

set aPosix to POSIX path of a

tell application id "com.adobe.photoshop"
  open file aPosix
end tell

★Click Here to Open This Script 

PDFのオープンはこちらです。PDFをbounding boxでトリミングしてオープンするのは、Cocoaの機能を利用してもなかなか骨が折れるので、かえってPhotoshopを呼び出してPDF→画像変換を行うほうが簡単なようです。

AppleScript名:Photoshop CCでPDFをオープンする
set aFile to (choose file)
set aPOSIX to POSIX path of aFile

set aPage to 1
set aResol to 300

tell application id "com.adobe.photoshop"
  open file aPOSIX as PDF with options {class:PDF open options, page:aPage, crop page:bounding box, resolution:aResol, mode:RGB}
end tell

★Click Here to Open This Script 

Posted in file Image PDF | Tagged 10.12savvy 10.13savvy 10.14savvy Photoshop | Leave a comment

リストの差分を取得して、登場順序が変わっていても1D List同士の登場要素が同じかをチェック

Posted on 5月 27, 2019 by Takaaki Naganoya

2つの1D List(1次元配列)同士の全要素をチェックし、登場順序に変更があったとしても要素自体に差がないかどうかをチェックするAppleScriptです。

……ソートしてから比較すれば、もっと短くて済むような気もしないでもないですが、もし違った場合には何が足りなくて(minusitems)、何が余計なのか(additems)をレポートしてくれるので実用的だと思います。

AppleScript名:リストの差分を取得して、登場順序が変わっていても1D List同士の登場要素が同じかをチェック
— Created 2019-05-27 by Takaaki Naganoya
— 2019 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

set aList to {3, 2, 1, 7, 6, 4}
set bList to {1, 2, 3, 4, 6, 7}
set a1Res to checkAllItemsAreSame(aList, bList) of me
–> true (配列要素の登場順序が変わっていても要素はすべて同じ)

set aList to {3, 2, 1, 7, 6}
set bList to {1, 2, 3, 4, 6, 7}
set a2Res to checkAllItemsAreSame(aList, bList) of me
–> addItems:{4}, minusItems:{}}–配列要素に過不足があった

–1D List同士の全要素が(登場順序が変更になっていても)同じかどうかをチェック
on checkAllItemsAreSame(aList, bList)
  set dRes to getDiffBetweenLists(aList, bList) of me
  
set ddRes to (dRes is equal to {addItems:{}, minusItems:{}}) as boolean
  
if ddRes = true then
    return true
  else
    return dRes
  end if
end checkAllItemsAreSame

–1D List同士のdiffを検出
on getDiffBetweenLists(aArray as list, bArray as list)
  set allSet to current application’s NSMutableSet’s setWithArray:aArray
  
allSet’s addObjectsFromArray:bArray
  
  
–重複する要素のみ抜き出す
  
set duplicateSet to current application’s NSMutableSet’s setWithArray:aArray
  
duplicateSet’s intersectSet:(current application’s NSSet’s setWithArray:bArray)
  
  
–重複部分を削除する
  
allSet’s minusSet:duplicateSet
  
set resArray to (allSet’s allObjects()) as list
  
  
set aSet to current application’s NSMutableSet’s setWithArray:aArray
  
set bSet to current application’s NSMutableSet’s setWithArray:resArray
  
aSet’s intersectSet:bSet –積集合
  
set addRes to aSet’s allObjects() as list
  
  
set cSet to current application’s NSMutableSet’s setWithArray:bArray
  
cSet’s intersectSet:bSet –積集合
  
set minusRes to cSet’s allObjects() as list
  
  
return {addItems:minusRes, minusItems:addRes}
end getDiffBetweenLists

★Click Here to Open This Script 

Posted in list Record | Tagged 10.12savvy 10.13savvy 10.14savvy NSMutableSet NSSet | Leave a comment

Photosで選択中の写真をKeynoteの現在の書類の現在のスライド以降に配置 v2

Posted on 5月 27, 2019 by Takaaki Naganoya

Photosで選択中の写真をKeynoteで現在オープン中の書類の現在のスライド(ページ)以降に配置していくAppleScriptの改良版です。

作業の過程をiPhoneで写真撮影。撮影した写真を写真.app(Photos.app)経由でKeynote書類にまとめる作業を行なっていました。作業工程を時間こみで表示できないとわかりにくかったので、Keynoteの各スライドに時刻を入れるようにAppleScriptを書いておきました。

初版では写真.app(Photos)上の選択項目を一切ソートなどしなかったため、exifから取得した撮影日付で昇順ソートしています。


▲写真.app(Photos)上でKeynoteに配置したい写真を選択


▲あらかじめKeynote上でマスタースライド「画像(横長)」上のアイテムを編集しておくといいかも


▲AppleScriptによって写真.app上の写真をKeynote書類上に順次割り付け。タイトル部分にexifに記録されていた撮影時刻が入る


▲実行結果。写真.appから割り付けた写真は撮影日時でソートされている

AppleScript名:Photosで選択中の写真をKeynoteの現在の書類の現在のスライド以降に配置 v2
—
–  Created by: Takaaki Naganoya
–  Created on: 2019/05/26
—
–  Copyright © 2019 Piyomaru Software, All Rights Reserved
—
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"
use BPlus : script "BridgePlus" –https://www.macosxautomation.com/applescript/apps/BridgePlus.html
use mdLib : script "Metadata Lib" version "2.0.0" –https://www.macosxautomation.com/applescript/apps/Script_Libs.html#Metadata_Lib

property NSUUID : a reference to current application’s NSUUID
property NSString : a reference to current application’s NSString
property SMSForder : a reference to current application’s SMSForder
property NSFileManager : a reference to current application’s NSFileManager

tell application "Keynote"
  if (count every document) = 0 then return
end tell

–Photosで選択中の写真をすべて書き出してalias listを取得する
set aList to exportSelectedPhotoOnPhotos() of me
if aList = {} or aList = false then return

set aLen to length of aList

–書き出した画像の親フォルダを求めておく(あとで削除するため)
tell application "Finder"
  set parentFol to parent of (item 1 of aList)
end tell

–exifから撮影日時を取得して2D List化
set aaList to {}
repeat with i in aList
  set j to contents of i
  
set exifDate to readExifDateTimeOriginal(j) of me
  
set the end of aaList to {j, exifDate, (time string of exifDate)}
end repeat

–撮影日時で昇順ソート
set aaaList to sortList2DAscending(aaList, {2}) of me

tell application "Keynote"
  tell front document
    tell current slide
      set curNum to slide number –現在表示中のスライドの番号(ページ数)を取得する
    end tell
    
    
–Photosから取得した写真のアイテム数でループ
    
repeat with i from 1 to aLen
      copy (item i of aaaList) to {aPhoto, aDateObj, creTime}
      
      
set newSlide to make new slide at slide (curNum + i) with properties {base slide:master slide "画像(横長)"} –This item is localized!! Maybe a "Photo"
      
      
tell newSlide
        set object text of default title item to creTime
        
set file name of image 1 to aPhoto –place an image to image placeholder
      end tell
      
      
–配置画像を削除
      
tell application "Finder"
        delete aPhoto –配置した写真を削除
      end tell
    end repeat
  end tell
end tell

–あとしまつ
tell application "Finder"
  delete parentFol –画像のダウンロードフォルダを削除
end tell

–Photosで選択中のファイルをtmporaryフォルダに書き出してalias listで返す
on exportSelectedPhotoOnPhotos()
  set dtPath to (path to temporary items) as text
  
set aUUID to NSUUID’s UUID()’s UUIDString() as text
  
  
set dirPath to ((POSIX path of dtPath) & aUUID)
  
set fileManager to NSFileManager’s defaultManager()
  
set aRes to (fileManager’s createDirectoryAtPath:dirPath withIntermediateDirectories:true attributes:(missing value) |error|:(reference))
  
set dtPath to dtPath & aUUID
  
  
tell application "Photos"
    set a to selection
    
if a = {} then return {}
    
set aRes to (export a to file dtPath)
  end tell
  
  
tell application "Finder"
    tell folder dtPath
      set fList to (every file) as alias list
    end tell
  end tell
  
  
if fList = {} then return false
  
return fList
end exportSelectedPhotoOnPhotos

–指定JPEG画像のExif情報からDateTimeOriginalを取得してAS dateオブジェクトに変換して返す
on readExifDateTimeOriginal(aTargFileAlias)
  set theMetadata to readMetadataFrom(aTargFileAlias) of me
  
if theMetadata = false then return false
  
  
set keysList to theMetadata’s allKeys()
  
  
if "{Exif}" is not in (keysList as list) then return false
  
  
set exifDate to theMetadata’s valueForKeyPath:"{Exif}.DateTimeOriginal"
  
if exifDate = missing value then return false
  
  
set a to NSString’s stringWithString:exifDate
  
set {aDateStr, aTimeStr} to (a’s componentsSeparatedByString:" ") as list
  
set bDateStr to repChar(aDateStr, ":", "/") of me
  
set fullDate to date (bDateStr & " " & aTimeStr)
  
  
return fullDate
end readExifDateTimeOriginal

–指定のファイルからメタデータを取得する
on readMetadataFrom(imageFile)
  load framework
  
set {theRecord, theError} to SMSForder’s metadataFromImage:imageFile |error|:(reference)
  
if theRecord = missing value then — there was a problem, so extract the error description
    error false
  else
    return theRecord
  end if
end readMetadataFrom

–文字置換
on repChar(origText as string, targChar as string, repChar as string)
  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

–入れ子のリストを昇順ソート
on sortList2DAscending(a, keyItem)
  return sort2DList(a, keyItem, {true}) of me
end sortList2DAscending

–入れ子のリストを降順ソート
on sortList2DDecending(a, keyItem)
  return sort2DList(a, keyItem, {false}) of me
end sortList2DDecending

–2D Listをソート
on sort2DList(aList as list, sortIndexes as list, sortOrders as list)
  load framework
  
  
–index値をAS流(アイテムが1はじまり)からCocoa流(アイテムが0はじまり)に変換
  
set newIndex to {}
  
repeat with i in sortIndexes
    set j to contents of i
    
set j to j – 1
    
set the end of newIndex to j
  end repeat
  
  
set sortTypes to {}
  
repeat (length of sortIndexes) times
    set the end of sortTypes to "compare:"
  end repeat
  
  
set resList to (SMSForder’s subarraysIn:(aList) sortedByIndexes:newIndex ascending:sortOrders sortTypes:sortTypes |error|:(missing value)) as {missing value, list}
  
  
return resList
end sort2DList

★Click Here to Open This Script 

Posted in Calendar exif file Image list | Tagged 10.12savvy 10.13savvy 10.14savvy Finder Keynote NSFileManager NSString NSUUID Photos | Leave a comment

Photosで選択中の写真をKeynoteの現在の書類の現在のスライド以降に配置

Posted on 5月 27, 2019 by Takaaki Naganoya

Photosで選択中の写真をKeynoteで現在オープン中の書類の現在のスライド(ページ)以降に配置していくAppleScriptです。

作業の過程をiPhoneで写真撮影。撮影した写真を写真.app(Photos.app)経由でKeynote書類にまとめる作業を行なっていました。作業工程を時間こみで表示できないとわかりにくかったので、Keynoteの各スライドに時刻を入れるようにAppleScriptを書いておきました(同じ作業が二度あるかは不明ですが、二度目からは明らかに時間の節約。つまり時間の貯金ができることになります)。

写真.app(Photos)上でKeynoteに配置したい写真を選択しておき、本Scriptを実行します。

Keynote書類上に新規スライドを追加し、撮影時刻と写真を配置していきます。

実行直後にPhotosで選択中の写真をファイルに書き出すため、若干待たされます。

# 複数のマシンでiCloudを介して写真を同期した場合に、写真.appのライブラリの写真の並び順は撮影日時どおりにならないようなので、明示的にソートしておく必要があるようです

ちなみに、写真の自作キーボードキットはこの後フットペダルにつなぎなおして、PPSSPP用の足踏みコントローラー化する予定です(「戦場の絆ポータブル」用)。

AppleScript名:Photosで選択中の写真をKeynoteの現在の書類の現在のスライド以降に配置
—
–  Created by: Takaaki Naganoya
–  Created on: 2019/05/26
—
–  Copyright © 2019 Piyomaru Software, All Rights Reserved
—
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"
use BPlus : script "BridgePlus" –https://www.macosxautomation.com/applescript/apps/BridgePlus.html
use mdLib : script "Metadata Lib" version "2.0.0" –https://www.macosxautomation.com/applescript/apps/Script_Libs.html#Metadata_Lib

property NSUUID : a reference to current application’s NSUUID
property NSString : a reference to current application’s NSString
property NSFileManager : a reference to current application’s NSFileManager

tell application "Keynote"
  if (count every document) = 0 then return
end tell

–Photosで選択中の写真をすべて書き出してalias listを取得する
set aList to exportSelectedPhotoOnPhotos() of me
if aList = {} or aList = false then return

set aLen to length of aList

–書き出した画像の親フォルダを求めておく(あとで削除するため)
tell application "Finder"
  set parentFol to parent of (item 1 of aList)
end tell

tell application "Keynote"
  tell front document
    tell current slide
      set curNum to slide number –現在表示中のスライドの番号(ページ数)を取得する
    end tell
    
    
–Photosから取得した写真のアイテム数でループ
    
repeat with i from 1 to aLen
      set aPhoto to contents of item i of aList
      
set newSlide to make new slide at slide (curNum + i) with properties {base slide:master slide "画像(横長)"} –This item is localized!! Maybe a "Photo"
      
set creTime to getCreationTime(aPhoto) of me
      
tell newSlide
        set object text of default title item to creTime
        
set file name of image 1 to aPhoto –place an image to image placeholder
      end tell
      
      
–配置画像を削除
      
tell application "Finder"
        delete aPhoto –配置した写真を削除
      end tell
    end repeat
  end tell
end tell

–あとしまつ
tell application "Finder"
  delete parentFol –画像のダウンロードフォルダを削除
end tell

–指定のaliasからExif情報の作成日の時刻情報を返す
on getCreationTime(anAlias)
  set exifDate to readExifDateTimeOriginal(anAlias) of me
  
return time string of exifDate
end getCreationTime

–Photosで選択中のファイルをtmporaryフォルダに書き出してalias listで返す
on exportSelectedPhotoOnPhotos()
  set dtPath to (path to temporary items) as text
  
set aUUID to NSUUID’s UUID()’s UUIDString() as text
  
  
set dirPath to ((POSIX path of dtPath) & aUUID)
  
set fileManager to NSFileManager’s defaultManager()
  
set aRes to (fileManager’s createDirectoryAtPath:dirPath withIntermediateDirectories:true attributes:(missing value) |error|:(reference))
  
set dtPath to dtPath & aUUID
  
  
tell application "Photos"
    set a to selection
    
if a = {} then return {}
    
set aRes to (export a to file dtPath)
  end tell
  
  
tell application "Finder"
    tell folder dtPath
      set fList to (every file) as alias list
    end tell
  end tell
  
  
if fList = {} then return false
  
return fList
end exportSelectedPhotoOnPhotos

–指定JPEG画像のExif情報からDateTimeOriginalを取得してAS dateオブジェクトに変換して返す
on readExifDateTimeOriginal(aTargFileAlias)
  set theMetadata to readMetadataFrom(aTargFileAlias) of me
  
if theMetadata = false then return false
  
  
set keysList to theMetadata’s allKeys()
  
  
if "{Exif}" is not in (keysList as list) then return false
  
  
set exifDate to theMetadata’s valueForKeyPath:"{Exif}.DateTimeOriginal"
  
if exifDate = missing value then return false
  
  
set a to NSString’s stringWithString:exifDate
  
set {aDateStr, aTimeStr} to (a’s componentsSeparatedByString:" ") as list
  
set bDateStr to repChar(aDateStr, ":", "/") of me
  
set fullDate to date (bDateStr & " " & aTimeStr)
  
  
return fullDate
end readExifDateTimeOriginal

–指定のファイルからメタデータを取得する
on readMetadataFrom(imageFile)
  load framework
  
set {theRecord, theError} to current application’s SMSForder’s metadataFromImage:imageFile |error|:(reference)
  
if theRecord = missing value then — there was a problem, so extract the error description
    error false
  else
    return theRecord
  end if
end readMetadataFrom

–文字置換
on repChar(origText as string, targChar as string, repChar as string)
  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

★Click Here to Open This Script 

Posted in Calendar exif file Image list | Tagged 10.12savvy 10.13savvy 10.14savvy Finder Keynote NSFileManager NSString NSUUID Photos | 1 Comment

URLにリソースが存在するかチェック v5(NSURLSession)

Posted on 5月 24, 2019 by Takaaki Naganoya

指定URLの存在確認を行うAppleScriptです。

以前はNSURLConnectionを使って確認するものを使っていましたが、NSURLSessionへと移行しようかというところ。

もちろん、shellのcurlコマンドを使えば数行で済んでしまいますが、そこをあえてCocoaの機能を利用して、というよりはちょっと前に書いたREST API呼び出しのサブルーチンが絶好調で動いているので、これをそのまま流用してみました。

ライブラリ化して自分のScriptのバンドル内に入れておくとか、~/Library/Script Librariesフォルダに入れておくとか、そういう使い方になると思います。自分でもわざわざこれだけの機能のために、これだけの量のコードをゼロから書くことは……めったにありません。

AppleScript名:URLにリソースが存在するかチェック(curl版)_v2
set aURL to "http://www.apple.com/jp/"
set aRes to chekURLExistence(aURL) of me

on chekURLExistence(aURL)
  try
    set aRes to do shell script ("/usr/bin/curl -LI " & aURL)
  on error
    return false
  end try
  
return ((aRes contains "HTTP/1.1 200") or (aRes contains "HTTP/2 200")) as boolean
end chekURLExistence

★Click Here to Open This Script 

AppleScript名:URLにリソースが存在するかチェック v5(NSURLSession)
— Created 2019-05-24 by Takaaki Naganoya
— 2019 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

property |NSURL| : a reference to current application’s |NSURL|
property NSString : a reference to current application’s NSString
property NSURLSession : a reference to current application’s NSURLSession
property NSJSONSerialization : a reference to current application’s NSJSONSerialization
property NSMutableURLRequest : a reference to current application’s NSMutableURLRequest
property NSUTF8StringEncoding : a reference to current application’s NSUTF8StringEncoding
property NSURLSessionConfiguration : a reference to current application’s NSURLSessionConfiguration

property retData : missing value
property retCode : 0
property retHeaders : 0
property drecF : false

set aURL to "http://piyocast.com/as/"
set uRes to chekURLExistence(aURL) of me
–> true

on chekURLExistence(aURL as string)
  set webRes to callRestGETAPIAndParseResults(aURL, 5) of me
  
return ((retCode of webRes) as integer = 200)
end chekURLExistence

— 指定URLにファイル(画像など)が存在するかチェック
–> {存在確認結果(boolean), レスポンスヘッダー(NSDictionary), データ(NSData)}
on callRestGETAPIAndParseResults(reqURLStr as string, timeOutSec as real)
  set (my retData) to false
  
set (my retCode) to 0
  
set (my retHeaders) to {}
  
set (my drecF) to false
  
  
set aURL to |NSURL|’s URLWithString:reqURLStr
  
set aRequest to NSMutableURLRequest’s requestWithURL:aURL
  
aRequest’s setHTTPMethod:"GET"
  
aRequest’s setValue:"gzip" forHTTPHeaderField:"Content-Encoding"
  
aRequest’s setValue:"application/json; charset=UTF-8" forHTTPHeaderField:"Content-Type"
  
  
set aConfig to NSURLSessionConfiguration’s defaultSessionConfiguration()
  
set aSession to NSURLSession’s sessionWithConfiguration:aConfig delegate:(me) delegateQueue:(missing value)
  
set aTask to aSession’s dataTaskWithRequest:aRequest
  
  
set hitF to false
  
aTask’s resume() –Start URL Session
  
  
repeat (1000 * timeOutSec) times
    if (my drecF) = true then
      set hitF to true
      
exit repeat
    end if
    
delay ("0.001" as real)
  end repeat
  
  
if hitF = false then error "REST API Timeout Error"
  
  
return {retData:retData, retCode:retCode, retHeaders:retHeaders}
end callRestGETAPIAndParseResults

on URLSession:tmpSession dataTask:tmpTask didReceiveData:tmpData
  parseSessionResults(tmpSession, tmpTask, tmpData) of me
  
set (my drecF) to true
end URLSession:dataTask:didReceiveData:

–ないとエラーになるので足した。とくに何もしていない
on URLSession:tmpSession dataTask:tmpTask willCacheResponse:cacheRes completionHandler:aHandler
  —
end URLSession:dataTask:willCacheResponse:completionHandler:

on parseSessionResults(aSession, aTask, tmpData)
  set aRes to aTask’s response()
  
set (my retCode) to aRes’s statusCode()
  
set (my retHeaders) to aRes’s allHeaderFields()
  
  
set resStr to NSString’s alloc()’s initWithData:tmpData encoding:(NSUTF8StringEncoding)
  
set jsonString to NSString’s stringWithString:(resStr)
  
  
set jsonData to jsonString’s dataUsingEncoding:(NSUTF8StringEncoding)
  
set aJsonDict to NSJSONSerialization’s JSONObjectWithData:jsonData options:0 |error|:(missing value)
  
  
set (my retData) to aJsonDict as anything
end parseSessionResults

★Click Here to Open This Script 

Posted in Network Record URL | Tagged 10.12savvy 10.13savvy 10.14savvy NSJSONSerialization NSMutableURLRequest NSString NSURL NSURLSession NSURLSessionConfiguration NSUTF8StringEncoding | Leave a comment

ScriptDebuggerでオープン中のScriptをScriptBundleに

Posted on 5月 23, 2019 by Takaaki Naganoya

ScriptDebuggerを使っていて、この作業がひんぱんに発生するのでScriptで自動化しました。

AppleScript書類を編集していて、バンドル内にFrameworkなどを突っ込みたいのにフラットなAppleScript書類(.scpt)だったので、そのままでは突っ込めず、コピペで新規バンドル書類(.scptd)を作成して、同じ名前で保存し直す作業です。

とてもとても標準機能で実装されていそうな内容ですが、子細に調査して存在していなかったので(ASObjC Explorerにはあったような気が)、ささっとAppleScriptで実装してScriptDebuggerのスクリプトメニューに入れて使っています。

ウィンドウの表示座標をきっちりそろえるとか、オリジナルのScriptを新規Scriptの作成後にクローズするとか、作りたくなってウズウズしてくる(自分的な)完成度の低さですが、そこでかっちり作り込むと「仕事中にちょっとだけ作るScript」の域を超えてしまうので、自制した次第です。

「すでに、バンドル形式のScriptが同一フォルダ内に存在する場合には警告を出して処理を中止する」か、あるいは「ファイル名に子番号をつけて重複を回避する」ぐらいの処理は足してもいいような気がします。


▲初期状態。フラットなAppleScript(.scpt)で書かれていたので、バンドル内にいろいろ追加できない状態


▲本Scriptの実行後の状態。ファイル名は拡張子を「.scptd」に変更しただけの状態

AppleScript名:ScriptをScript Bundleに
— Created 2019-05-23 by Takaaki Naganoya
— 2019 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

tell application "Script Debugger"
  tell front document
    set myType to script type
    
if myType = bundled compiled script then
      display notification "There is no need to convert…."
      
return
    end if
    
    
set mySource to source text
    
set mySpec to file spec
    
    
try
      close with saving
    on error
      display notification "Can not save this Script. So I quited conversion process…."
      
return
    end try
  end tell
end tell

–ファイルパスの拡張子を付け替えてFileに変換
set pathString to current application’s NSString’s stringWithString:(POSIX path of mySpec)
set newPath to ((pathString’s stringByDeletingPathExtension())’s stringByAppendingPathExtension:"scptd") as string
set aFile to POSIX file newPath

–ファイル拡張子を付け替えた新規ファイル名で保存
tell application "Script Debugger"
  set aDoc to make new document with properties {source text:mySource, script type:bundled compiled script}
  
tell aDoc
    set aRes to compile –構文確認(ねんのため)
    
if aRes = false then return
    
    
–compileを通った場合のみファイル保存を行う
    
save in aFile
  end tell
end tell

★Click Here to Open This Script 

Posted in file File path | Tagged 10.12savvy 10.13savvy 10.14savvy ScriptDebugger | 1 Comment

Keynoteで表示中のスライド上の表を2つ、縦方向に連結する

Posted on 5月 21, 2019 by Takaaki Naganoya

Keynoteでオープン中の書類の表示中のスライド(ページ)上にある表を2つ選択して、縦方向に連結するAppleScriptです。

実行頻度から、横連結だけでいいかと思っていたのですが、結局縦連結のScriptも書いておきました。たぶん、こっち(縦連結)は(個人的には)使わないでしょう。

一定の実用性を確保するためには、各表のヘッダー行のラベルを見て、同じラベルのデータを同じ列に入れる必要があることでしょう。本Scriptの実装レベルだと、物理的にただ表をつなげるだけです。

また、ヘッダー部分の処理は一切行っていません。実用性を考えればヘッダー行やヘッダー列を無視して、データ部のみ連結するといった処理が必要になってくると思います。現状の実装では「(作った本人が)わかっているから別にそこまでしなくていい」という程度のお手軽実装です。


▲マージ対象の表


▲現在表示中のスライド(ページ)中に存在している表のタイトルが一覧表示される。座標位置をもとに上→下、左→右とソートした順で表示


▲複数項目を選択する場合にはCommandキーを押しながら選択


▲2つの表を縦方向にマージ(連結)。マージされたほうの表は削除

macOS 10.14.5+Keynote v9.0.2で作成および動作確認を行っています。macOS 10.14上ではBridgePlusを呼び出すためにScript Debugger上で実行するか、アプレット書き出しして実行する必要があります。または、アプレット書き出ししてスクリプトメニューから呼び出してもよいでしょう。

# 個人的には、めんどくさいのでmacOS 10.14環境ではSIP(System Integrity Protection)をオフにして使っています

macOS 10.13.x、macOS 10.12.xでは普通にスクリプトエディタなどから実行可能です。

AppleScript名:Keynoteで表示中のスライド上の表を2つ、縦方向に連結する.scpt
— Created 2019-05-21 by Takaaki Naganoya
— 2019 Piyomaru Software
use AppleScript version "2.4" — Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
use Bplus : script "BridgePlus" –https://www.macosxautomation.com/applescript/apps/BridgePlus.html

tell application "Keynote"
  tell front document
    tell current slide
      set tCount to count every table
      
if tCount < 2 then
        display dialog "There is no tables to merge" buttons {"OK"} default button 1
        
return
      end if
      
      
set tList to every table
      
set tInfoList to {}
      
repeat with i in tList
        set {tPosX, tPosY} to position of i
        
set tName to name of i
        
set the end of tInfoList to {tName, tPosX, tPosY}
      end repeat
    end tell
  end tell
end tell

–表のY座標、X座標で昇順ソート(上→下、左→右の順で並べる)
set sortedList to sort2DList(tInfoList, {3, 2}, {true, true}) of me

–表リストから名前だけ抽出
set tmpTList to retSpecifiedItemFrom2DList({1}, sortedList) of me

–マージ対象のテーブルを名称で選択
set tRes to choose from list tmpTList with title "Vertial Merge Tables" with prompt "Select merge target two table names " & return & "(Sorted Up-> Down, Left->Right)" with multiple selections allowed
if tRes = false then
  display dialog "Canseled" buttons {"OK"} default button 1
  
return
end if

if length of tRes is not equal to 2 then
  display dialog "Select *two* tables" buttons {"OK"} default button 1
  
return
end if

–set mDirection to contents of (choose from list {"Vertival", "Horizontal"} with title "Select Merge Direction" without empty selection allowed)
set mDirection to "Vertival"

set f1Table to contents of item 1 of tRes –Left (Original)
set f2Table to contents of item 2 of tRes –Right (merged)

tell application "Keynote"
  tell front document
    tell current slide
      –マージ先の表のサイズを取得(幅、高さ)
      
tell table f1Table
        set f1Width to column count
        
set f1Height to row count
      end tell
      
      
–マージされるの表のサイズを取得(幅、高さ、データを2D Listで)
      
tell table f2Table
        set f2Width to column count
        
set f2Height to row count
        
set f2DatList to {}
        
repeat with i from 1 to f2Height
          tell row i
            set aRowDat to value of every cell
          end tell
          
set the end of f2DatList to aRowDat
        end repeat
      end tell
      
      
–マージ先の表のサイズを変更して新規追加したセルにデータを埋める
      
tell table f1Table
        set row count to row count + f2Height –表リサイズ
        
        
set rowCount to f1Height + 1
        
repeat with i in f2DatList
          set colCount to 1
          
          
tell row rowCount
            repeat with ii in i
              set jj to contents of ii
              
              
if jj is not equal to missing value then –空白セルを処理スキップ
                tell cell colCount
                  set value to jj
                end tell
              end if
              
              
set colCount to colCount + 1
            end repeat
          end tell
          
          
set rowCount to rowCount + 1
        end repeat
      end tell
      
      
delete table f2Table
    end tell
  end tell
end tell

–2D Listをソート
on sort2DList(aList as list, sortIndexes as list, sortOrders as list)
  load framework
  
–index値をAS流(アイテムが1はじまり)からCocoa流(アイテムが0はじまり)に変換
  
set newIndex to {}
  
repeat with i in sortIndexes
    set j to contents of i
    
set j to j – 1
    
set the end of newIndex to j
  end repeat
  
  
–Sort TypeのListを作成(あえて外部から指定する内容でもない)
  
set sortTypes to {}
  
repeat (length of sortIndexes) times
    set the end of sortTypes to "compare:"
  end repeat
  
  
set resList to (current application’s SMSForder’s subarraysIn:(aList) sortedByIndexes:newIndex ascending:sortOrders sortTypes:sortTypes |error|:(missing value)) as list
  
return resList
end sort2DList

–指定2Dリストから、各要素の指定アイテム目を取り出して(1D Listで)返す
on retSpecifiedItemFrom2DList(aList as list, bList as list)
  set newList to {}
  
repeat with i in aList
    repeat with ii in bList
      set j to contents of ii
      
set a to contents of (item i of j)
      
set the end of newList to a
    end repeat
  end repeat
  
return newList
end retSpecifiedItemFrom2DList

★Click Here to Open This Script 

Posted in list | Tagged 10.12savvy 10.13savvy 10.14savvy Keynote | Leave a comment

Microsoft EdgeのMac版がCanaryチャンネルでプレビュー公開。AS対応

Posted on 5月 21, 2019 by Takaaki Naganoya

Microsoft製のWebブラウザが久しぶりにmacOSに帰ってきました。Microsoft EdgeのMac版がCanaryチャンネルでプレビュー公開されました。Chromiumベースで開発されているというか、まんまChromiumともいえる状態であり、ファーストリリースでありながらAppleScriptのサポート機能が搭載されています。

AppleScript非対応のWebブラウザはダウンロードしても100%ゴミ箱行きになるため、対応しているのはいいことです。ただし、ChromeのScriptingで不満に思っている点は100% Edgeでも再現します。

FileMergeでsdefの差分をチェックしてみたら、差は検出されませんでした。挙動もほぼChromeと同じです。今のところアプリケーション名が「Microsoft Edge Canary」(Bundle ID=com.microsoft.Edge.Canary)であるため、正式リリース時にはこの「Canary」が外れるものと思われます。

AppleScript名:Edge Canaryの情報を取得する
tell application "Microsoft Edge Canary"
  properties
  
–> {bookmarks bar:bookmark folder id 1 of application "Microsoft Edge Canary", frontmost:false, other bookmarks:bookmark folder id 2 of application "Microsoft Edge Canary", class:application, name:"Microsoft Edge Canary", version:"76.0.161.0"}
end tell

★Click Here to Open This Script 

AppleScript名:Edge CanaryにBundle IDでアクセスする
tell application id "com.microsoft.Edge.Canary"
  properties
  
–> {bookmarks bar:bookmark folder id 1 of application "Microsoft Edge Canary", frontmost:false, other bookmarks:bookmark folder id 2 of application "Microsoft Edge Canary", class:application, name:"Microsoft Edge Canary", version:"76.0.161.0"}
end tell

★Click Here to Open This Script 

AppleScript名:Edge Canaryの現在のウィンドウの現在のタブの情報にアクセスする
tell application "Microsoft Edge Canary"
  tell window 1
    tell active tab
      properties
      
–> {URL:"chrome://settings/help", name:"Settings", loading:false, class:tab, id:8}
      
–> {URL:"http://piyocast.com/as/", name:"AppleScriptの穴 – Useful & Practical AppleScript archive. Click ’★Click Here to Open This Script’ Link to download each AppleScript", loading:false, class:tab, id:2}
    end tell
  end tell
end tell

★Click Here to Open This Script 

AppleScript名:Edge Canaryで指定URLをオープンする
tell application "Microsoft Edge Canary"
  make new window
  
tell window 1
    tell tab 1
      set URL to "https://www.apple.com/jp"
    end tell
  end tell
end tell

★Click Here to Open This Script 

AppleScript名:Edge Canaryで指定のローカルのHTMLを表示する
set anAlias to choose file

tell application "Finder"
  set aURL to URL of anAlias
end tell

tell application "Microsoft Edge Canary"
  open location aURL
end tell

★Click Here to Open This Script 

Posted in sdef | Tagged 10.12savvy 10.13savvy 10.14savvy Microsoft Edge | Leave a comment

Keynoteで表示中のスライド上の表を2つ、横方向に連結する

Posted on 5月 21, 2019 by Takaaki Naganoya

Keynoteでオープン中の書類の表示中のスライド(ページ)上にある表を2つ選択して、横方向に連結するAppleScriptです。

Keynoteで資料を作っていて、あまりにこういう処理が多いのでScript化しました。縦方向に連結してもいいのですが(最初は連結方向を選択させかけた)、実際に扱っている表が横長のケースが(個人的に)多いので「横連結だけでいいや」ということに。


▲マージ対象の表


▲現在表示中のスライド(ページ)中に存在している表のタイトルが一覧表示される。座標位置をもとに上→下、左→右とソートした順で表示


▲複数項目を選択する場合にはCommandキーを押しながら選択


▲2つの表を横方向にマージ(連結)。マージされたほうの表は削除

macOS 10.14.5+Keynote v9.0.2で作成および動作確認を行っています。macOS 10.14上ではBridgePlusを呼び出すためにScript Debugger上で実行するか、アプレット書き出しして実行する必要があります。または、アプレット書き出ししてスクリプトメニューから呼び出してもよいでしょう。

# 個人的には、めんどくさいのでmacOS 10.14環境ではSIP(System Integrity Protection)をオフにして使っています

macOS 10.13.x、macOS 10.12.xでは普通にスクリプトエディタなどから実行可能です。

AppleScript名:Keynoteで表示中のスライド上の表を2つ、横方向に連結する.scpt
— Created 2019-05-21 by Takaaki Naganoya
— 2019 Piyomaru Software
use AppleScript version "2.4" — Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
use Bplus : script "BridgePlus" –https://www.macosxautomation.com/applescript/apps/BridgePlus.html

tell application "Keynote"
  tell front document
    tell current slide
      set tCount to count every table
      
if tCount < 2 then
        display dialog "There is no tables to merge" buttons {"OK"} default button 1
        
return
      end if
      
      
set tList to every table
      
set tInfoList to {}
      
repeat with i in tList
        set {tPosX, tPosY} to position of i
        
set tName to name of i
        
set the end of tInfoList to {tName, tPosX, tPosY}
      end repeat
    end tell
  end tell
end tell

–表のY座標、X座標で昇順ソート(上→下、左→右の順で並べる)
set sortedList to sort2DList(tInfoList, {3, 2}, {true, true}) of me

–表リストから名前だけ抽出
set tmpTList to retSpecifiedItemFrom2DList({1}, sortedList) of me

–マージ対象のテーブルを名称で選択
set tRes to choose from list tmpTList with title "Select Merge Tables" with prompt "Select merge target two table names " & return & "(Sorted Up-> Down, Left->Right)" with multiple selections allowed
if length of tRes is not equal to 2 then
  display dialog "Select *two* tables"
  
return
end if

–set mDirection to contents of (choose from list {"Vertival", "Horizontal"} with title "Select Merge Direction" without empty selection allowed)
set mDirection to "Horizontal"

set f1Table to contents of item 1 of tRes –Left (Original)
set f2Table to contents of item 2 of tRes –Right (merged)

tell application "Keynote"
  tell front document
    tell current slide
      –マージ先の表のサイズを取得(幅、高さ)
      
tell table f1Table
        set f1Width to column count
        
set f1Height to row count
      end tell
      
      
–マージされるの表のサイズを取得(幅、高さ、データを2D Listで)
      
tell table f2Table
        set f2Width to column count
        
set f2Height to row count
        
set f2DatList to {}
        
repeat with i from 1 to f2Height
          tell row i
            set aRowDat to value of every cell
          end tell
          
set the end of f2DatList to aRowDat
        end repeat
      end tell
      
      
–マージ先の表のサイズを変更して新規追加したセルにデータを埋める
      
tell table f1Table
        set column count to column count + f2Width –表リサイズ
        
        
set rowCount to 1
        
repeat with i in f2DatList
          set colCount to (f1Width + 1)
          
          
tell row rowCount
            repeat with ii in i
              set jj to contents of ii
              
              
if jj is not equal to missing value then –空白セルを処理スキップ
                tell cell colCount
                  set value to jj
                end tell
              end if
              
              
set colCount to colCount + 1
            end repeat
          end tell
          
          
set rowCount to rowCount + 1
        end repeat
      end tell
      
      
delete table f2Table
    end tell
  end tell
end tell

return f2DatList

–2D Listをソート
on sort2DList(aList as list, sortIndexes as list, sortOrders as list)
  load framework
  
–index値をAS流(アイテムが1はじまり)からCocoa流(アイテムが0はじまり)に変換
  
set newIndex to {}
  
repeat with i in sortIndexes
    set j to contents of i
    
set j to j – 1
    
set the end of newIndex to j
  end repeat
  
  
–Sort TypeのListを作成(あえて外部から指定する内容でもない)
  
set sortTypes to {}
  
repeat (length of sortIndexes) times
    set the end of sortTypes to "compare:"
  end repeat
  
  
set resList to (current application’s SMSForder’s subarraysIn:(aList) sortedByIndexes:newIndex ascending:sortOrders sortTypes:sortTypes |error|:(missing value)) as list
  
return resList
end sort2DList

–指定2Dリストから、各要素の指定アイテム目を取り出して(1D Listで)返す
on retSpecifiedItemFrom2DList(aList as list, bList as list)
  set newList to {}
  
repeat with i in aList
    repeat with ii in bList
      set j to contents of ii
      
set a to contents of (item i of j)
      
set the end of newList to a
    end repeat
  end repeat
  
return newList
end retSpecifiedItemFrom2DList

★Click Here to Open This Script 

Posted in list Sort | Tagged 10.12savvy 10.13savvy 10.14savvy Keynote | Leave a comment

Keynoteの各slideのtitleから目次のテキストを作成してNumbersの表を作成

Posted on 5月 20, 2019 by Takaaki Naganoya

現在オープン中の最前面のKeynote書類の各スライド(ページ)のタイトルを取得して、Numbersの新規書類上にページとタイトルの一覧表を作成するAppleScriptです。

こういうのが、一番オーソドックスで誰でも「そういうのがあったら楽なのに」と思わせるような用途でしょう。

Keynoteの書類を作成してページ数が増え、タイトル一覧をながめつつ削除したりアップデートしたりする対象を探したいような場合に、このような一覧表を作成させるとわかりやすくて便利です。

本Scriptは本当にありもののルーチンをつなげて最低限の処理を行わせたものですが、さらに手の込んだ処理を行うことも可能です。たとえば、別途Keynote書類をスライド(ページ)ごとに画像書き出ししておいて、Numbersのセル上にプレビュー画像として入れておくとか。あるいは、Keynote書類の各スライドのマスターアイテム名を見て処理を変えるとか。実にいろいろあります。

作成と動作確認はmacOS 10.14.5+Keynote 9.0.2で行っていますが、macOS 10.13/10.12でも動作するはずですしました。

AppleScript名:Keynoteの各slideのtitleから目次のテキストを作成してNumbersの表を作成
—
–  Created by: Takaaki Naganoya
–  Created on: 2019/05/20
—
–  Copyright © 2019 Piyomaru Software, All Rights Reserved

use AppleScript version "2.4" — Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

–Keynoteの各slideのタイトルを取得する
tell application "Keynote"
  tell document 1
    set aList to object text of default title item of every slide
  end tell
end tell

set aLen to (length of aList) + 1 –ヘッダー行の分を+1
set bLen to 2 –data width (columns)

–2D Listを作成する (Page, Title)
set newList to {}
set pCount to 1
repeat with i in aList
  set j to contents of i
  
set the end of newList to {pCount as string, j}
  
set pCount to pCount + 1
end repeat

–Numbersの書類を新規作成して、指定サイズの表を作成する
makeNewNumbersDocumentAndTable(aLen, bLen) of me

–作成した新規書類の表1に2D Listを入れる(ただし、100行分ぐらいを上限とする。それ以上は別途CSVを書き出してオープンさせたほうが圧倒的に高速)I
fillCurrentTable(newList) of me

on fillCurrentTable(aList)
  set aLen to length of aList
  
set aWidth to length of first item of aList
  
  
tell application "Numbers"
    tell front document
      tell active sheet
        tell table 1
          repeat with i from 1 to aLen
            tell row (i + 1)
              set aRowList to contents of item i of aList
              
repeat with ii from 1 to aWidth
                tell cell ii
                  set aTmpData to contents of item ii of aRowList
                  
ignoring application responses
                    set value to aTmpData
                  end ignoring
                end tell
              end repeat
            end tell
          end repeat
        end tell
      end tell
    end tell
  end tell
end fillCurrentTable

on makeNewNumbersDocumentAndTable(aHeight, aWidth)
  tell application "Numbers"
    make new document
    
    
tell front document
      tell active sheet
        delete every table
      end tell
    end tell
    
    
tell front document
      tell active sheet
        set tRes to make new table with properties {row count:aHeight, column count:aWidth}
        
return tRes
      end tell
    end tell
  end tell
end makeNewNumbersDocumentAndTable

★Click Here to Open This Script 

Posted in list | Tagged 10.11savvy 10.12savvy 10.13savvy 10.14savvy Keynote Numbers | Leave a comment

2D Listの行列入れ替え(transpose)

Posted on 5月 16, 2019 by Takaaki Naganoya

2D List(2次元配列)の行列入れ替えを行うAppleScriptです。

本プログラムは前の(2018.1.31に消える前の)Blogに掲載していたものを動作検証を行いつつ再掲載したもので、そもそもはShane StanleyのBridgePlus AppleScript Libraryのドキュメントに掲載されているもの、ほぼそのままです。

BridgePlusの前身であるASObjCExras.frameworkのときにこの機能を見つけて、どうしてこの機能がこの仕様になっているのか、その当時は理解できていませんでした。

2次元配列の回転だけなら、単純にデータを(画像のように)回転させるだけの処理のはずですが(→ 時計まわりに90度回すサンプル)、そういうわけでもない。なんでこんな処理をShaneが書いたのか理解できず、当時は「なーんか使えないメソッドがついてんなー」ぐらいにしか思っていませんでした。

そして、出会ってしまったわけです。この機能がバリバリに必要なデータに。そして、深く理解しました。これはShaneが説明不足すぎです。そして、「致命的に必要な機能」だったので最初からついていたわけです。

ExcelでもNumbersでもGoogle Spreadsheetでも、1レコードといったら行ごとに配置されているのが普通です。プログラマーを10人集めて、2次元配列でそういうデータを表現しろと言われたら、世界中のどこのプログラマーでもだいたい10人とも行ごとにレコードを表現すると思います。

そんな中、1レコード=1行ではなく1レコード=1列とかいうデータがやってきて、途方に暮れたすえにNumbers上で「行と列を転置」機能を利用して縦横の入れ替えを行なって、ハッと気づきました。

 「これや……このためについとったんや」

調べてみたら、ビンゴ! まさに2D Listのtransposeのための機能がBridgePlusの、

SMSForder's colsToRowsIn:① |error|:②

だったわけです。

「プログラミングの身体性」ともいうべきものがあります。実体験をもとにするとデータやオブジェクトをどのように操作すべきなのかを深く理解でき、逆に実体験がともなっていないとまったく理解できないという話であり、これがまさにそれだったのでしょう(AppleScriptってプログラミングの身体性の塊のような気も、、、、一般のプログラマーが仕様だけ読んで組もうとして挫折した話をウンザリするほど聞くもので。実際にアプリケーションを動かしてみないと理解できないことが多すぎです)。

なので、こういう「息を飲むような非常識なデータ」を前に途方に暮れないかぎり、このメソッドの有用性は理解できないと思います(自分がそうだったので)。

AppleScript名:2D Listの行列入れ替え.scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2019/05/16
—
–  Copyright © 2019 Piyomaru Software, All Rights Reserved
—
use AppleScript version "2.4" — Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
use script "BridgePlus" –https://www.macosxautomation.com/applescript/apps/BridgePlus.html

set aList to {{"r0", "f1", "f2"}, {"r1", "f1r1", "f2r1"}, {"r2", "f1r2", "f2r2"}, {"r3", "f1r3", "f2r3"}}
set bList to transpose2DList(aList) of me
–> {{"r0", "r1", "r2", "r3"}, {"f1", "f1r1", "f1r2", "f1r3"}, {"f2", "f2r1", "f2r2", "f2r3"}}

on transpose2DList(aList as list)
  load framework
  
return (ASify from (current application’s SMSForder’s colsToRowsIn:aList |error|:(missing value)))
end transpose2DList

★Click Here to Open This Script 

Posted in list | Tagged 10.11savvy 10.12savvy 10.13savvy 10.14savvy Excel Numbers | Leave a comment

Keynoteのexport optionsにバグ

Posted on 5月 14, 2019 by Takaaki Naganoya

Keynoteのdocumentをmovieに書き出す(export)際に指定するオプションにバグがあることに気づきました。

AppleScript Users ML上でNigel Garvey氏に検証に付き合っていただきました。同氏にはこの場を借りて感謝の言葉を申し上げる次第です。

確認したのはv8.3および最新のv9.0.2ですが、実際にはv7.1で発生した変更によって起こったものと推測されています。

上記のように、手元のアプリケーションは(ほぼ)すべてのバージョンについてAppleScript用語辞書をHTMLに書き出してあり、diffにより差分チェックを行なっています。赤いタグ(ラベル)がついているのが変更があったバージョンで、この履歴をたどるとv7.0のexport optionsは、

movie format small / medium / large -- format for exported movie.

となっていましたが、Keynote v7.1において、

movie format 360p / 540p / 720p / 1080p / 2160p / native size -- format for exported movie.

と変更されました。実際にこれらのオプションを指定すると、構文確認時にエラーになります。AppleScriptで数値で始まる予約語(例:1080p)や演算記号を含む予約語(例:C++)は使えないので、そもそも言語仕様的に無理なものをsdefに定義しています。Appleの担当者の頭が沸いているとしか思えません。素人以下です。

それぞれ、small / medium / largeというsynonymが定義されているため、{movie format: large}などと入力して構文確認できますが、synonymでしかないため元のキーワードにフォワードされます。結果として、{movie format: 720p} と解釈され、エラーになります。

これは、AppleScriptの処理系の問題ではなくKeynote側の実装が間違っているためです(一切動作確認をしていないんでしょう)。

解決策はとくにありませんが、オリジナルサイズを指定する「native size」オプションだけはエラーにならないため、同オプションを指定するしかないと思います。

AppleScript名:KeynoteからのMovie書き出し
set targetFileHFSPath to (choose file name) as string –かならずファイル拡張子に「.m4v」を指定する必要がある

with timeout of 3600 seconds
  tell application "Keynote"
    export front document to file targetFileHFSPath as QuickTime movie with properties {movie format:native size}
  end tell
end timeout

★Click Here to Open This Script 

Posted in Bug | Tagged 10.11savvy 10.12savvy 10.13savvy 10.14savvy Keynote | 1 Comment

macOS 10.14.5

Posted on 5月 14, 2019 by Takaaki Naganoya

■和暦の「令和」対応

macOSでは10.14.5にアップデートしないと「令和」表示にならないもよう。ただし、和暦は日常的には(個人的に)ほとんど使っていないので影響はあるんだかないんだかわかりません。

■Notarized Service

macOS 10.14.5より、Kernel Extension/アプリケーションについては、distribute(Mac App Store経由の配布を意図しているものと思われる)にはNotarize(公証)サービスをパスすることが要求されるようになりました。

コード署名:ビルド時、およびアプリケーション書き出し時にApple開発アカウントの署名(開発者IDによる署名)を行う
Sandbox:Mac App Storeに提出するアプリケーションにおいて、Sandbox環境を前提としたランタイム環境で実行する(Xcodeのみ)
Notarize(公証):実行バイナリの内容にコンピュータに対して害をなすような処理内容が含まれていないか、AppleのNotarizedサービスを呼び出すことで自動的に検証・証明される

コード署名以上、Mac App Storeへのアプリ審査以下、という説明をされていますが、Sandboxが前提とかいうのは無茶な気がします。

macOS 10.15上でも、さらにNotarize(公証)サービスと連携した機能が提供されることでしょう。

現時点において、自分が自分のMac上でAppleScriptで作成したアプリケーションについて、公証サービスを通しておく必要はありません。ただし、Webを通じて不特定多数に対してアプレット/アプリケーションを配布するとか、仕事で実行バイナリを納品するような場合には必要になるかもしれません。少なくとも、Mac App Store上でAppleScriptによって記述したアプリケーションを配布する場合には必要になってきます。

ただ、あのAppleの公証サービスが本当にコンピュータに有害な処理を検出できるのか? 誤って有害ではない処理を有害判定するのではないか、という疑問はついて回ります(かのmacOS 10.13をリリースさせたTim Cook体制のやることなんて信用できない)。Sandboxで禁止されている処理ぐらいは、かんたんに回避して実行できましたし。

誤って「有害な処理を行なっている」と判定されたアプリケーションの異議申し立てや、誤って有害判定されたDevelopper IDをAppleが機械的に無効化したり、Bannするような間抜けな事態の発生が予想できすぎです(Developper向けのMailing Listが落ちて、連絡しても1か月放置するような会社にそんなものを運用する能力があるのでしょうか?)。

自分でビルドしてコード署名してNotarizedしたFrameworkぐらいは自分のホームディレクトリ下に置いて呼び出したいところです。macOS 10.14のSIPによる制限は非常にかったるくて生産性が下がります。あるいは、スクリプトエディタからもっとシステムよりのFrameworksフォルダに入れたフレームワークを呼び出せるようにするとか。

なお、Shane Stanley@Late Night Softwareが、このNotarizeサービスにアプリケーションを認証するツールを用意し、配布しています(なんとスクリプタブル!)。この、考えただけで憂鬱になるNotarizeサービスにアプリケーションを通す作業も、自動で行うことで不快感が軽減されるかもしれません。

SD NOTARY: NOTARIZING MADE EASY

SD Notary: Notarizing Made Easy

Posted in Notarization Security | Tagged 10.14savvy | Leave a comment

Mail.appで未読メール数を取得する

Posted on 5月 14, 2019 by Takaaki Naganoya

Mail.appで未読メールを取得するAppleScriptです。

まず、「未読メール」とは何かという話があります。未読メールとは、「まだ読んでいないメール」のことです。つまり、すべてのメッセージに未読/既読のフラグが用意されています。

極論すれば、すべてのメッセージの未読/既読状態を調べる必要があるわけですが、さすがにそれだと実用性がいまひとつなので、メールフォルダごとに未読メッセージのカウントが求められるようになっています。

一般的に「未読メール」といった場合、サブフォルダに仕分けしたメールの未読件数ではなく、受信メールボックス(INBOX)に入っている未読メールをカウントすることになることでしょう。

ただし、Mail.appには複数のメールアカウントを登録できるようになっているため、受信メールボックスのうちそれぞれのアカウントに該当するものが別々に返ってくることになります。

Apple純正のアプリケーションの多くはAppleScriptのオブジェクト名までローカライズされている(過剰ローカライズ)ことが多いのですが、Mail.appについては受信ボックス(=受信トレイ)は「INBOX」となっており、その他のボックスについても(ゴミ箱とか)ローカライズされていません。

画面上の表記 AppleScript上で指定する場合の名称
受信 INBOX
VIP —-
フラグ付き —-
下書き Drafts
送信済み Sent Messages
迷惑メール Junk
ゴミ箱 Deleted Messages
アーカイブ Archive
AppleScript名:メールアカウント名の一覧を取得
tell application "Mail"
  set nameList to name of every account
end tell
–> {"iCloud", "maro@XXXXXXXX"}

★Click Here to Open This Script 

AppleScript名:各アカウントのINBOXフォルダの未読メールを取得する
tell application "Mail"
  set tmpCount to unread count of mailbox "INBOX" of every account
end tell
–> {0, 0}–メールアカウントの数だけ配列要素が返ってくる

★Click Here to Open This Script 

AppleScript名:すべてのINBOXの未読メール数を合計して返す
set aCount to countAllUnreadMessages()
–> 0

on countAllUnreadMessages()
  tell application "Mail"
    set aCount to count every account
    
    
set totalUnreadCount to 0
    
repeat with i from 1 to aCount
      set tmpCount to unread count of mailbox "INBOX" of account i
      
set totalUnreadCount to totalUnreadCount + tmpCount
    end repeat
  end tell
  
  
return totalUnreadCount
end countAllUnreadMessages

★Click Here to Open This Script 

Posted in list | Tagged 10.12savvy 10.13savvy 10.14savvy Mail | Leave a comment

矩形座標同士の衝突判定(共通部分の検出) v3b

Posted on 5月 8, 2019 by Takaaki Naganoya

矩形座標(NSRect)同士の衝突判定を行うAppleScriptのmacOS 10.13以降対応改修版です。

macOS 10.13以降への対応を行う際に注意すべきなのは、NSRectやboundsを取得するScriptが異なる結果を返してこないか、確認を行うことです。

set bRect to current application's NSMakeRect(20, 90, 50, 120)
--> {origin:{x:20.0, y:90.0}, |size|:{width:50.0, height:120.0}}
--> {{20.0, 90.0}, {50.0, 120.0}}--10.13, 10.14, 10.15, 11.0

その中でも矩形同士の衝突(重なり)判定はとくに書き換えが必要な箇所です。

実際に、Adobe Illustratorのデータ上で複数製品のデータが並んで掲載されているケースで、製品ごとに別のマスキングレイヤー上に色違いの矩形を配置することで、その矩形エリア内のIllustratorオブジェクトを特定する処理を行ったときに、本ルーチンを使用していたため(macOS 10.13/14対応のために)書き換えが必要になりました。

macOS 10.13/14対応のための、

{{0.0, 0.0}, {0.0, 0.0}}

の部分が一番重要なポイントです。これが、

{{0, 0}, {0, 0}}

だとうまく動作しません。ここ、ちょっとだけハマりました。

2019/05/10 追記
初版では、NSRectがrecordで返ってくるか(macOS 10.10, 10.11, 10.12)、listで返ってくるか(macOS 10.13, 10.14)をOSのバージョンで判定していました。これは実際のところ間違いではないのですが、OSのバグなのか仕様の公式な変更なのか不明なため、たとえばNSNotFoundの定義値が間違っていたバグなどはmacOS 10.13.1で修正されるなど、マイナーバージョンアップで仕様が変わるケースも観測されています。そのため、OSバージョンを見て判定することは将来的に危険であると判断し、データの型を判定する方法に書き換えました(書き捨てレベルのルーチンなので、型判定を行う書き方もよくしています)。

AppleScript名:矩形座標同士の衝突判定(共通部分の検出) v3b
— Created 2017-03-06 by Takaaki Naganoya
— Modified 2019-05-10 by Takaaki Naganoya
— 2019 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

set a1Rect to {origin:{x:10, y:10}, |size|:{width:100, height:100}}
set b1Rect to {origin:{x:30, y:30}, |size|:{width:100, height:100}}
set a1Res to detectRectanglesCollision(a1Rect, b1Rect) of me
–>  true
–>  true–macOS 10.13, 10.14

set a4Rect to {origin:{x:0, y:20}, |size|:{width:100, height:10}}
set b4Rect to {origin:{x:1000, y:10000}, |size|:{width:50, height:100}}
set a2Res to detectRectanglesCollision(a4Rect, b4Rect) of me
–>  false
–>  false–macOS 10.13, 10.14

set a3Rect to {origin:{x:30, y:30}, |size|:{width:50, height:50}}
set b3Rect to {origin:{x:10, y:10}, |size|:{width:100, height:100}}
set a3Res to detectRectanglesCollision(a3Rect, b3Rect) of me
–> true
–> true–macOS 10.13, 10.14

set a4Rect to {origin:{x:0, y:20}, |size|:{width:100, height:10}}
set b4Rect to {origin:{x:10, y:10}, |size|:{width:50, height:100}}
set a4Res to detectRectanglesCollision(a4Rect, b4Rect) of me
–> true
–> true–macOS 10.13, 10.14

return {a1Res, a2Res, a3Res, a4Res}

–NSRect同士の衝突判定
on detectRectanglesCollision(aRect, bRect)
  set a1Res to (current application’s NSIntersectionRect(aRect, bRect)) as {record, list}
  
set tmpClass to class of a1Res
  
  
if tmpClass = record then
    –macOS 10.10, 10.11, 10.12
    
return not (a1Res = {origin:{x:0.0, y:0.0}, |size|:{width:0.0, height:0.0}})
  else if tmpClass = list then
    –macOS 10.13 or later
    
return not (a1Res = {{0.0, 0.0}, {0.0, 0.0}})
  end if
end detectRectanglesCollision

★Click Here to Open This Script 

Posted in Record | Tagged 10.11savvy 10.12savvy 10.13savvy 10.14savvy NSRect | 1 Comment

Keynote書類の現在のスライド上の選択中の表の背景色を置換 v2

Posted on 5月 4, 2019 by Takaaki Naganoya

Keynoteでオープン中の最前面の書類の現在表示中のスライドに存在する選択中の表オブジェクトの背景色を置換するAppleScriptです。

–> Keynote_table_color_replace v2 Run-Only (Download Run-only script with Framework and Library)

初版ではtable 1を決め打ちで指定していましたが、選択中の表オブジェクトへの参照を取得するルーチンを組み込んで、選択中の表を処理できるように機能アップしました。

Scriptの状態で、macOS 10.12.6+Keynote v8.1上で動作確認。Appletの状態で、macOS 10.14.4/10.13.6+Keynote v9.0.1上で動作確認してあります。

本Scriptは大量のセルを持つ表を高速に色置換するために作成したものなので、時間がかかってもよくてのんびり色置換するだけでよければ、このコードの10分の1以下で書けます。

(1)セルを1つずつ塗るのではなく、複数セルを一度に塗る高速化
(2)セルの連続範囲を縦方向と横方向にセル連続区間を検出・カウントを実行。どちらか処理が早く終わる方を採用(処理前に2方向でシミュレーション)
(3)Keynoteとの間で非同期処理を行って処理高速化
(4)色選択のためにカラーポップアップメニューを、独自で作成したウィンドウ上に表示
(5)色の内容を把握しやすいように、色のRGB数値から色名をその場で生成
(6)カラーポップアップ上に表示する色プレビューを角丸で表示

といった高速化、高機能化のための実装をふんだんに投下しています。これらをすべて撤去すれば相当に記述量は少なくて済むことでしょう。

AppleScript名:Keynote書類の現在のスライド上の選択中の表の背景色を置換 v2
— Created 2019-01-29 by Takaaki Naganoya
— Modified 2019-05-04 by Takaaki Naganoya
— 2019 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"
use framework "dbColNamesKit" –https://github.com/daniel-beard/DBColorNames/
use Bplus : script "BridgePlus" –https://www.macosxautomation.com/applescript/apps/BridgePlus.html

–v1:Convert Pages version to Keynote
–v2:Prepare Selected Table

property NSView : a reference to current application’s NSView
property NSColor : a reference to current application’s NSColor
property NSArray : a reference to current application’s NSArray
property NSMenu : a reference to current application’s NSMenu
property NSImage : a reference to current application’s NSImage
property NSScreen : a reference to current application’s NSScreen
property NSButton : a reference to current application’s NSButton
property NSWindow : a reference to current application’s NSWindow
property NSTextField : a reference to current application’s NSTextField
property NSMenuItem : a reference to current application’s NSMenuItem
property NSBezierPath : a reference to current application’s NSBezierPath
property NSPopUpButton : a reference to current application’s NSPopUpButton
property NSWindowController : a reference to current application’s NSWindowController
property NSTitledWindowMask : a reference to current application’s NSTitledWindowMask
property NSRoundedBezelStyle : a reference to current application’s NSRoundedBezelStyle
property NSFloatingWindowLevel : a reference to current application’s NSFloatingWindowLevel
property NSBackingStoreBuffered : a reference to current application’s NSBackingStoreBuffered
property NSMomentaryLightButton : a reference to current application’s NSMomentaryLightButton

property windisp : true
property wController : missing value
property pop1ind : 1

–初期化
set (my windisp) to true
set (my pop1ind) to 1
load framework

–選択中のTableオブジェクトへの参照を取得する
set theTable to getSelectedTable() of me

–選択中のTableオブジェクトの塗り色をすべて取得
tell application "Keynote"
  tell theTable
    set c1List to background color of every cell
    
set aProp to properties
    
set xCount to column count of aProp
  end tell
end tell

–Convert 1D List to 2D List
set c3List to (current application’s SMSForder’s subarraysFrom:c1List groupedBy:xCount |error|:(missing value)) as list

–色データをユニーク化(重複削除)
set bList to uniquifyList(c1List) of me

–missing value(背景色なし)を除外する
set c2List to (current application’s SMSForder’s arrayByDeletingBlanksIn:(bList)) as list

–Popup Menuで置換色選択
set paramObj to {c2List, 65535, "OK", "Select Target Color", 180} –Timeout = 180 sec, Color val range = 16bit
my performSelectorOnMainThread:"getPopupValues:" withObject:(paramObj) waitUntilDone:true
if pop1ind = false then return –timed out
set fromCol to (contents of item pop1ind of c2List)

–カラーピッカーで置換色選択
set tCol to choose color default color fromCol

set d1 to current date

–実際に表の背景色を置換する
set hitList to findDataFrom2DList(fromCol, c3List) of me –データ上で当該色のセル情報を計算する

–Rangeを横スキャンと縦スキャンの2通りで試算(Two way Simulation)
set rList1 to retRangeFromPosListHorizontal(hitList) of me –横方向へのrange評価
set rList2 to retRangeFromPosListVertival(hitList) of me –縦方向へのrange評価

–Simulationの結果、要素数の少ない方(=処理時間の短い方=高速な方)を採用する
log {"Simulation", (length of rList1), (length of rList2)}
if (length of rList1) < (length of rList2) then
  copy rList1 to rangeList
else
  copy rList2 to rangeList
end if

tell application "Keynote"
  activate
  
  
tell theTable
    repeat with i in rangeList
      set j to contents of i
      
      
ignoring application responses –非同期実行モードで高速実行
        set background color of range j to tCol
      end ignoring
      
    end repeat
  end tell
  
end tell

set d2 to current date
return d2 – d1

on getSelectedTable()
  tell application "Keynote"
    tell front document
      tell current slide
        try
          set theTable to first table whose class of selection range is range
        on error
          set tCount to count every table
          
if tCount = 0 then
            error "No Selected Table Objects…"
          else
            –選択セルがない場合はTable 1を全選択
            
set theTable to table 1
          end if
        end try
        
        
return theTable
      end tell
    end tell
  end tell
end getSelectedTable

–カラーポップアップメニューをウィンドウ表示
on getPopupValues:paramObj
  copy (paramObj as list) to {ap1List, aColMax, aButtonMSG, aSliderValMSG, timeOutSecs}
  
  
set (my windisp) to true
  
  
set aView to NSView’s alloc()’s initWithFrame:(current application’s NSMakeRect(0, 0, 360, 100))
  
  
–Labelをつくる
  
set a1TF to NSTextField’s alloc()’s initWithFrame:(current application’s NSMakeRect(30, 60, 80, 20))
  
a1TF’s setEditable:false
  
a1TF’s setStringValue:"Color:"
  
a1TF’s setDrawsBackground:false
  
a1TF’s setBordered:false
  
  
–Ppopup Buttonをつくる
  
set a1Button to NSPopUpButton’s alloc()’s initWithFrame:(current application’s NSMakeRect(80, 60, 200, 20)) pullsDown:false
  
a1Button’s removeAllItems()
  
  
set a1Menu to NSMenu’s alloc()’s init()
  
set aCDB to current application’s DBColorNames’s alloc()’s init()
  
  
set iCount to 1
  
repeat with i in ap1List
    copy i to {r1, g1, b1}
    
    
set nsCol to makeNSColorFromRGBAval(r1, g1, b1, aColMax, aColMax) of me
    
set anImage to makeRoundedNSImageWithFilledWithColor(64, 64, nsCol, 4) of me
    
    
set aTitle to "#" & (iCount as string) & " " & (aCDB’s nameForColor:nsCol) as string
    
set aMenuItem to (NSMenuItem’s alloc()’s initWithTitle:aTitle action:"actionHandler:" keyEquivalent:"")
    (
aMenuItem’s setImage:anImage)
    (
aMenuItem’s setEnabled:true)
    (
a1Menu’s addItem:aMenuItem)
    
    
set iCount to iCount + 1
  end repeat
  
  
a1Button’s setMenu:a1Menu
  
  
  
–Buttonをつくる
  
set bButton to (NSButton’s alloc()’s initWithFrame:(current application’s NSMakeRect(80, 10, 140, 40)))
  
bButton’s setButtonType:(NSMomentaryLightButton)
  
bButton’s setBezelStyle:(NSRoundedBezelStyle)
  
bButton’s setTitle:aButtonMSG
  
bButton’s setTarget:me
  
bButton’s setAction:("clicked:")
  
bButton’s setKeyEquivalent:(return)
  
  
aView’s addSubview:a1TF
  
  
aView’s addSubview:a1Button
  
aView’s addSubview:bButton
  
aView’s setNeedsDisplay:true
  
  
–NSWindowControllerを作ってみた(いらない?)
  
set aWin to (my makeWinWithView(aView, 300, 100, aSliderValMSG))
  
  
set wController to NSWindowController’s alloc()
  
wController’s initWithWindow:aWin
  
  
wController’s showWindow:me
  
  
set aCount to timeOutSecs * 100
  
  
set hitF to false
  
repeat aCount times
    if (my windisp) = false then
      set hitF to true
      
exit repeat
    end if
    
delay 0.01
    
set aCount to aCount – 1
  end repeat
  
  
my closeWin:aWin
  
  
if hitF = true then
    set s1Val to ((a1Button’s indexOfSelectedItem() as number) + 1)
  else
    set s1Val to false
  end if
  
  
copy s1Val to my pop1ind
  
end getPopupValues:

on clicked:aSender
  set (my windisp) to false
end clicked:

–make Window for Display
on makeWinWithView(aView, aWinWidth as integer, aWinHeight as integer, aTitle as string)
  set aScreen to NSScreen’s mainScreen()
  
set aFrame to {{0, 0}, {aWinWidth, aWinHeight}}
  
  
set aBacking to NSTitledWindowMask
  
  
set aDefer to NSBackingStoreBuffered
  
  
— Window
  
set aWin to NSWindow’s alloc()
  (
aWin’s initWithContentRect:aFrame styleMask:aBacking backing:aDefer defer:false screen:aScreen)
  
  
aWin’s setTitle:aTitle
  
aWin’s setDelegate:me
  
aWin’s setDisplaysWhenScreenProfileChanges:true
  
aWin’s setHasShadow:true
  
aWin’s setIgnoresMouseEvents:false
  
aWin’s setLevel:(NSFloatingWindowLevel)
  
aWin’s setOpaque:false
  
aWin’s setReleasedWhenClosed:true
  
aWin’s |center|()
  
  
aWin’s setContentView:aView
  
  
return aWin
end makeWinWithView

–close win
on closeWin:aWindow
  repeat with n from 10 to 1 by -1
    (aWindow’s setAlphaValue:n / 10)
    
delay 0.02
  end repeat
  
aWindow’s |close|()
end closeWin:

–Popup Action Handler
on actionHandler:sender
  set aTag to tag of sender as integer
  
set aTitle to title of sender as string
end actionHandler:

–aMaxValを最大値とする数値でNSColorを作成して返す
on makeNSColorFromRGBAval(redValue as integer, greenValue as integer, blueValue as integer, alphaValue as integer, aMaxVal as integer)
  set aRedCocoa to (redValue / aMaxVal) as real
  
set aGreenCocoa to (greenValue / aMaxVal) as real
  
set aBlueCocoa to (blueValue / aMaxVal) as real
  
set aAlphaCocoa to (alphaValue / aMaxVal) as real
  
set aColor to NSColor’s colorWithCalibratedRed:aRedCocoa green:aGreenCocoa blue:aBlueCocoa alpha:aAlphaCocoa
  
return aColor
end makeNSColorFromRGBAval

–指定サイズのNSImageを作成し、指定色で塗ってNSImageで返す
on makeNSImageWithFilledWithColor(aWidth as integer, aHeight as integer, fillColor)
  set anImage to NSImage’s alloc()’s initWithSize:(current application’s NSMakeSize(aWidth, aHeight))
  
anImage’s lockFocus()
  
—
  
set theRect to {{x:0, y:0}, {height:aHeight, width:aWidth}}
  
set theNSBezierPath to NSBezierPath’s bezierPath
  
theNSBezierPath’s appendBezierPathWithRect:theRect
  
—
  
fillColor’s |set|() –色設定
  
theNSBezierPath’s fill() –ぬりつぶし
  
—
  
anImage’s unlockFocus()
  
—
  
return anImage
end makeNSImageWithFilledWithColor

–指定サイズのNSImageを作成し、指定色で塗ってNSImageで返す、anRadiusの半径の角丸で
on makeRoundedNSImageWithFilledWithColor(aWidth as integer, aHeight as integer, fillColor, anRadius as real)
  set anImage to NSImage’s alloc()’s initWithSize:(current application’s NSMakeSize(aWidth, aHeight))
  
anImage’s lockFocus()
  
—
  
set theRect to {{x:0, y:0}, {height:aHeight, width:aWidth}}
  
set theNSBezierPath to NSBezierPath’s bezierPathWithRoundedRect:theRect xRadius:anRadius yRadius:anRadius
  
—
  
fillColor’s |set|() –色設定
  
theNSBezierPath’s fill() –ぬりつぶし
  
—
  
anImage’s unlockFocus()
  
  
return anImage
end makeRoundedNSImageWithFilledWithColor

on uniquifyList(aList as list)
  set aArray to NSArray’s arrayWithArray:aList
  
set bArray to aArray’s valueForKeyPath:"@distinctUnionOfObjects.self"
  
return bArray as list
end uniquifyList

on findDataFrom2DList(anItem, aList as list)
  script spd
    property aList : {}
    
property resList : {}
  end script
  
  
set (aList of spd) to aList
  
set (resList of spd) to {}
  
  
set yCount to 1
  
  
repeat with i in (aList of spd)
    
    
set aResList to (Bplus’s indexesOfItem:anItem inList:i inverting:false) as list
    
    
set tmpList to {}
    
if aResList is not equal to {} then
      repeat with ii in aResList
        set jj to contents of ii
        
set the end of tmpList to {jj, yCount}
      end repeat
      
set (resList of spd) to (resList of spd) & tmpList
    end if
    
    
set yCount to yCount + 1
  end repeat
  
  
return (resList of spd) –return {{x, y}…..} item list (1-based)
end findDataFrom2DList

on retRangeFromPosListVertival(posList as list)
  script rangeSPD
    property posList2 : {}
  end script
  
  
–縦方向へのrange評価に都合がいいようにソート
  
set (posList2 of rangeSPD) to shellSortListAscending(posList, {1, 2}) of me
  
  
–先頭データをピックアップ
  
set firstData to first item of (posList2 of rangeSPD)
  
set (posList2 of rangeSPD) to rest of (posList2 of rangeSPD)
  
  
copy firstData to {curX1, curY1}
  
set tmpRangeStr to aNumToExcelColumn(curX1) of me & (curY1 as string) & ":"
  
  
set tmpRange to {}
  
set hitF to false
  
  
set outList to {}
  
  
repeat with i in (posList2 of rangeSPD)
    copy i to {tmpX, tmpY}
    
    
–log {"{curX1, curY1}", {curX1, curY1}}
    
–log {"{tmpX, tmpY}", {tmpX, tmpY}}
    
    
    
if (curX1 = tmpX) and (curY1 + 1 = tmpY) then
      –Y方向への連続値を拾っている最中
      
if hitF = false then
        –log "case 1a"
        
–log {"hitF", hitF}
        
set hitF to true
      else
        –log "case 1b"
        
–log {"hitF", hitF}
        
–横に連続しているブロックの途中
      end if
    else
      –直前の値と連続していない
      
if hitF = false then
        –log "case 2a"
        
–log {"hitF", hitF}
        
set tmpRangeStr to tmpRangeStr & aNumToExcelColumn(curX1) of me & (curY1 as string)
        
set the end of outList to tmpRangeStr
        
set tmpRangeStr to aNumToExcelColumn(tmpX) of me & (tmpY as string) & ":"
        
set hitF to false
      else
        –log "case 2b"
        
–log {"hitF", hitF}
        
–連続ブロックの末尾を拾った
        
set tmpRangeStr to tmpRangeStr & aNumToExcelColumn(curX1) of me & (curY1 as string)
        
set the end of outList to tmpRangeStr
        
set tmpRangeStr to aNumToExcelColumn(tmpX) of me & (tmpY as string) & ":"
        
set hitF to false
        
–log {"tmpRangeStr", tmpRangeStr}
      end if
    end if
    
    
copy {tmpX, tmpY} to {curX1, curY1}
  end repeat
  
  
–log {tmpRangeStr, hitF}
  
  
if (hitF = true) or (tmpRangeStr is not equal to "") then
    set tmpRangeStr to tmpRangeStr & aNumToExcelColumn(curX1) of me & (curY1 as string)
    
set the end of outList to tmpRangeStr
  end if
  
  
return outList
end retRangeFromPosListVertival

on retRangeFromPosListHorizontal(posList as list)
  script rangeSPD
    property posList2 : {}
  end script
  
  
copy posList to (posList2 of rangeSPD)
  
  
–先頭データをピックアップ
  
set firstData to first item of (posList2 of rangeSPD)
  
set (posList2 of rangeSPD) to rest of (posList2 of rangeSPD)
  
  
copy firstData to {curX1, curY1}
  
set tmpRangeStr to aNumToExcelColumn(curX1) of me & (curY1 as string) & ":"
  
  
set tmpRange to {}
  
set hitF to false
  
  
set outList to {}
  
  
repeat with i in (posList2 of rangeSPD)
    copy i to {tmpX, tmpY}
    
    
–log {"{curX1, curY1}", {curX1, curY1}}
    
–log {"{tmpX, tmpY}", {tmpX, tmpY}}
    
    
    
if (curX1 + 1 = tmpX) and (curY1 = tmpY) then
      –X方向への連続値を拾っている最中
      
if hitF = false then
        –log "case 1a"
        
–log {"hitF", hitF}
        
set hitF to true
      else
        –log "case 1b"
        
–log {"hitF", hitF}
        
–横に連続しているブロックの途中
      end if
    else
      –直前の値と連続していない
      
if hitF = false then
        –log "case 2a"
        
–log {"hitF", hitF}
        
set tmpRangeStr to tmpRangeStr & aNumToExcelColumn(curX1) of me & (curY1 as string)
        
set the end of outList to tmpRangeStr
        
set tmpRangeStr to aNumToExcelColumn(tmpX) of me & (tmpY as string) & ":"
        
set hitF to false
      else
        –log "case 2b"
        
–log {"hitF", hitF}
        
–連続ブロックの末尾を拾った
        
set tmpRangeStr to tmpRangeStr & aNumToExcelColumn(curX1) of me & (curY1 as string)
        
set the end of outList to tmpRangeStr
        
set tmpRangeStr to aNumToExcelColumn(tmpX) of me & (tmpY as string) & ":"
        
set hitF to false
        
–log {"tmpRangeStr", tmpRangeStr}
      end if
    end if
    
    
copy {tmpX, tmpY} to {curX1, curY1}
  end repeat
  
  
–log {tmpRangeStr, hitF}
  
  
if (hitF = true) or (tmpRangeStr is not equal to "") then
    set tmpRangeStr to tmpRangeStr & aNumToExcelColumn(curX1) of me & (curY1 as string)
    
set the end of outList to tmpRangeStr
  end if
  
  
return outList
end retRangeFromPosListHorizontal

–2008/05/01 By Takaaki Naganoya
–10進数数値をExcel 2004/2008的カラム表現にエンコードするサブルーチン を使いまわし
–1〜1351までの間であれば正しいエンコーディング結果を返す
on aNumToExcelColumn(origNum as integer)
  if origNum > 1351 then
    error "エラー:Excel 2004/2008的カラム表現(A1形式)への変換ルーチンにおいて、想定範囲外(1351以上)のパラメータが指定されました"
  end if
  
  
set upperDigitEncTable to {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "A"}
  
set lowerDigitEncTable to {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "A"}
  
  
set oNum to origNum
  
set nTh to 26
  
set stringLength to 4
  
  
–数字が1桁の場合の対応
  
if origNum < 27 then
    set aRes to (item origNum of upperDigitEncTable) as string
    
return aRes
  end if
  
  
  
if origNum > 702 then
    –3桁になる場合
    
set upupNum to oNum div 676 –整数除算–上の上の桁
    
set oNum to oNum – (upupNum * 676)
    
set upNum to oNum div 26 –整数除算–上の桁
    
set lowNum to oNum mod 26 – 1 –余剰計算–下の桁
    
    
–超つじつま合わせ処理
    
if lowNum = -1 then
      set upNum to upNum – 1
      
set lowNum to 25
    end if
    
    
set upupChar to (item upupNum of upperDigitEncTable) as string
    
set upChar to (item upNum of upperDigitEncTable) as string
    
set lowChar to (item (lowNum + 1) of lowerDigitEncTable) as string
    
set resText to upupChar & upChar & lowChar
    
  else
    –2桁の場合
    
set upNum to oNum div 26 –整数除算–上の桁
    
set lowNum to oNum mod 26 – 1 –余剰計算–下の桁
    
    
–超つじつま合わせ処理
    
if lowNum = -1 then
      set upNum to upNum – 1
      
set lowNum to 25
    end if
    
    
set upChar to (item upNum of upperDigitEncTable) as string
    
set lowChar to (item (lowNum + 1) of lowerDigitEncTable) as string
    
set resText to upChar & lowChar
    
  end if
  
  
return resText
end aNumToExcelColumn

–入れ子のリストを昇順ソート
on shellSortListAscending(a, keyItem)
  return sort2DList(a, keyItem, {true}) of me
end shellSortListAscending

–入れ子のリストを降順ソート
on shellSortListDecending(a, keyItem)
  return sort2DList(a, keyItem, {false}) of me
end shellSortListDecending

–2D Listをソート
on sort2DList(aList as list, sortIndexes as list, sortOrders as list)
  
  
–index値をAS流(アイテムが1はじまり)からCocoa流(アイテムが0はじまり)に変換
  
set newIndex to {}
  
repeat with i in sortIndexes
    set j to contents of i
    
set j to j – 1
    
set the end of newIndex to j
  end repeat
  
  
–Sort TypeのListを作成(あえて外部から指定する内容でもない)
  
set sortTypes to {}
  
repeat (length of sortIndexes) times
    set the end of sortTypes to "compare:"
  end repeat
  
  
–Sort
  
set resList to (current application’s SMSForder’s subarraysIn:(aList) sortedByIndexes:newIndex ascending:sortOrders sortTypes:sortTypes |error|:(missing value)) as list
  
  
return resList
end sort2DList

★Click Here to Open This Script 

Posted in Color dialog GUI | Leave a comment

Keynoteで選択中の表を取得する

Posted on 5月 3, 2019 by Takaaki Naganoya

最前面に表示しているKeynote書類中の現在表示中のスライド(ページ)上の選択状態にある表オブジェクトへの参照を求めるAppleScriptです。

Keynote v9.0で、これまで実装されていなかった「selection」が実装されたものの、予約語として存在しているだけで機能アップはしていませんでした(Pages v8.0のついでにアップデート?)。

一方で、同様にselectionが実装されてこなかったにもかかわらず、普通に選択中の表オブジェクトへの参照を取得できているNumbersがあります(ちょっとトリッキーな書き方ですけれども)。

では、そのトリッキーな記述でKeynote上の選択状態にある表オブジェクトへの参照が取得できるのか? という疑問を持って実際に試してみたらできました、というのが本Scriptです。Keynote v8.1+macOS 10.12.6、Keynote v9.0.1+macOS 10.13.6、Keynote v9.0.1+macOS 10.14.4の組み合わせで動作確認しています。

実際に、表オブジェクトを選択して本Scriptを実行すると、表オブジェクトへの参照が得られます。

AppleScript名:Keynoteで選択中の表を取得する
tell application "Keynote"
  tell front document
    tell current slide
      try
        set theTable to first table whose class of selection range is range
      on error
        set tCount to count every table
        
if tCount = 0 then
          error "現在のスライド中に選択状態になっている表オブジェクトが存在しません"
        else
          –選択セルがない場合はTable 1を全選択
          
set theTable to table 1
        end if
      end try
      
      
tell theTable
        set aList to value of every cell
        
–> {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0}
      end tell
    end tell
  end tell
end tell

★Click Here to Open This Script 

Posted in How To | Tagged 10.11savvy 10.12savvy 10.13savvy 10.14savvy Keynote | 1 Comment

アラートダイアログ上にTextField x 2を表示 v2

Posted on 5月 2, 2019 by Takaaki Naganoya

アラートダイアログに簡易UIを実装して便利なダイアログ部品を整備する計画の一環として作成した、アラートダイアログにNSTextFieldを2つ+ラベル用のfield2つを作成して、ユーザーからの数値入力を取得するAppleScriptです。

スクリプトエディタ、ScriptDebuggerの両方で実行できますが、Script Menuから実行するとダイアログが最前面に表示されません。Script Menuから実行する場合にはAppleScript書類の状態で呼び出すのではなく、AppleScriptアプレットに書き出して呼び出すのがよいでしょう。

macOS 10.14上では本Scriptの実行は明確にメインスレッド上で行うことを要求されます。Control-Comand-Rで実行してください。

AppleScript名:アラートダイアログ上にTextField x 2を表示 v2
— Created 2019-05-02 by Takaaki Naganoya
— 2019 Piyomaru Software
use AppleScript version "2.5"
use scripting additions
use framework "Foundation"
use framework "AppKit"

property NSView : a reference to current application’s NSView
property NSAlert : a reference to current application’s NSAlert
property NSTextField : a reference to current application’s NSTextField
property NSRunningApplication : a reference to current application’s NSRunningApplication

property theResult : 0
property returnCode : 0

set paramObj to {myMessage:"Keynoteオブジェクトの2次元詰め込み", mySubMessage:"詰め込み先の矩形サイズを数値で入力してください", mes1:"幅", mes1Default:"900", mes2:"高さ", mes2Default:"500"}

set segRes to my simulateAndRetRect:paramObj
–> {a1Res:900, a2Res:500}

on simulateAndRetRect:paramObj
  –Receive Parameters
  
set aMainMes to (myMessage of paramObj) as string –Main Message
  
set aSubMes to (mySubMessage of paramObj) as string –Sub Message
  
set mes1Label to (mes1 of paramObj) as string –Text Input field 1 Label
  
set mes2Label to (mes2 of paramObj) as string –Text Input field 2 Label
  
set aTextInputString to (mes1Default of paramObj) as string –Text Input field 1 Default value
  
set bTextInputString to (mes2Default of paramObj) as string –Text Input field 2 Default value
  
  
— Create a view
  
set theView to NSView’s alloc()’s initWithFrame:(current application’s NSMakeRect(0, 0, 300, 60))
  
  
— create two input field and their labels pairs
  
–NSTextFields for Input
  
set aTextInput to makeNSTextField(100, 35, 140, 20, true, (aTextInputString), true, true) of me
  
set bTextInput to makeNSTextField(100, 0, 140, 20, true, (bTextInputString), true, true) of me
  
  
–Labels
  
set a1TF to makeNSTextField(0, 35, 100, 20, false, (mes1Label), false, false) of me
  
set a2TF to makeNSTextField(0, 0, 100, 20, false, (mes2Label), false, false) of me
  
  
theView’s setSubviews:{a1TF, aTextInput, a2TF, bTextInput}
  
  
— set up alert
  
set theAlert to NSAlert’s alloc()’s init()
  
tell theAlert
    its setMessageText:aMainMes
    
its setInformativeText:aSubMes
    
its addButtonWithTitle:"OK"
    
its addButtonWithTitle:"Cancel"
    
its setAccessoryView:theView
  end tell
  
  
— show alert in modal loop
  
NSRunningApplication’s currentApplication()’s activateWithOptions:0
  
my performSelectorOnMainThread:"doModal:" withObject:(theAlert) waitUntilDone:true
  
if (my returnCode as number) = 1001 then error number -128
  
  
set s1Val to (aTextInput’s integerValue()) as integer
  
set s2Val to (bTextInput’s integerValue()) as integer
  
  
return {a1Res:s1Val, a2Res:s2Val}
end simulateAndRetRect:

on doModal:aParam
  set (my returnCode) to aParam’s runModal()
end doModal:

on makeNSTextField(xPos as integer, yPos as integer, myWidth as integer, myHeight as integer, editableF as boolean, setVal as string, backgroundF as boolean, borderedF as boolean)
  set aNSString to NSTextField’s alloc()’s initWithFrame:(current application’s NSMakeRect(xPos, yPos, myWidth, myHeight))
  
aNSString’s setEditable:(editableF)
  
aNSString’s setStringValue:(setVal)
  
aNSString’s setDrawsBackground:(backgroundF)
  
aNSString’s setBordered:(borderedF)
  
return aNSString
end makeNSTextField

★Click Here to Open This Script 

Posted in GUI Text | Tagged 10.11savvy 10.12savvy 10.13savvy NSAlert NSRunningApplication NSTextField NSView | Leave a comment

GET method REST API v4.3

Posted on 5月 1, 2019 by Takaaki Naganoya

クラウド系のサービスを呼び出すためのAPIとして一般的なREST APIを呼び出すAppleScriptの最新版(のスケルトン)です。

# v4.2からv4.3にバージョンアップしました(2019/05/02)

macOS 10.10でほぼすべてのAppleScriptランタイムでCocoaの機能が利用できるようになったため、Cocoaの機能を利用してクラウド系サービスを呼び出すことを、割と早い時期から調査していました。

「ほぼすべて」と書いているのは、アプリケーション内蔵のScript Menu(iTunesとか)や、Folder Actionなどの独特なランタイム、あるいはMessages(旧称iChat)のメッセージ受信イベントから呼び出されるAppleScriptランタイムなど、それぞれのアプリケーション独自で実装している処理系についてはCocoaの機能が使えるかどうかは保証のかぎりではないからです。

明確に、当初からクラウドと機械学習をAppleScriptから利用するために、苦労してCocoaの機能を追いかけてきたわけです。その途中でいろいろサードパーティのFrameworkを呼び出せたりして、期待よりも大きな成果を手にしている昨今です。OSの内部機能を直接利用できることのメリットは、処理速度や詳細な情報取得など枚挙にいとまがありません(日本語の慣用句表現なので翻訳しにくいかも?)。

話をクラウドにもどしましょう。REST APIを呼び出すには、同期で実行されるNSURLConnectionを使うのが最も簡単で確実でした。

しかし、同APIは非推奨(近い将来に廃止される)という位置付けになったため、その代わりを探す必要に迫られました。すでにNSURLConnectionを用いて記述したREST API呼び出しのScriptが大量に存在していたからです。

代替APIとしてNSURLSessionが提示されましたが、こちらは非同期実行のみで同期実行モードはありません。いろいろ実験してみたものの、数回に1回ぐらい、サーバーからの応答をつかまえ損ねることがあり、処理時間もNSURLConnection版より長くかかります。

このため、「do shell script経由でcurlコマンドを使って回避するか?」といった回避策を検討していたところです。

そんな中、冗談半分でNSURLSessionを利用したバージョンをほんの少し修正してみたところ、いままでの不安定さが嘘のように安定して結果を得られるようになってきました。これはいい兆候です。

ただし、同時に問題点も見つかってきました。macOS標準装備のScript Editor上で実行する分には問題ないのですが、Script Debugger上で実行すると、macOS 10.12/10.13/10.14共通でサーバーからの応答を取得できず、タイムアウトエラーになります。

初回掲載時(v4.2)にはScript Debugger上でデータ受信を検出できないという問題がありました。データの受信用のプロパティがmissing valueでなければデータを受信した、という判定ロジックがうまく動いていない(どういう仕組みかはわからないものの、missing valueと判断され続けた? ラベル値とproperty名でコンフリクト起こしたかも?)現象が見られました。そこで、データの受信プロパティとデータ受信完了検出のプロパティを明確に分けて判定してみたところ、Script DebuggerやmacOS 10.14上でも問題なく動作することを確認しました。

AppleScript名:GET method REST API v4.3
— Created 2019-05-01 by Takaaki Naganoya
— 2019 Piyomaru Software
use AppleScript version "2.5"
use scripting additions
use framework "Foundation"
use framework "AppKit"

property |NSURL| : a reference to current application’s |NSURL|
property NSString : a reference to current application’s NSString
property NSURLSession : a reference to current application’s NSURLSession
property NSJSONSerialization : a reference to current application’s NSJSONSerialization
property NSMutableURLRequest : a reference to current application’s NSMutableURLRequest
property NSUTF8StringEncoding : a reference to current application’s NSUTF8StringEncoding
property NSURLSessionConfiguration : a reference to current application’s NSURLSessionConfiguration

property retData : missing value
property retCode : 0
property retHeaders : 0
property drecF : false

set reqURLStr to "http://jsonplaceholder.typicode.com/posts"
set aRESTres to callRestGETAPIAndParseResults(reqURLStr, 10) of me
–return retData of aRESTres

set aRESTcode to retCode of aRESTres
–return aRESTcode
–> 200

return retHeaders as record
–> {|content-type|:"application/json; charset=utf-8", Pragma:"no-cache", |x-powered-by|:"Express", |set-cookie|:"__cfduid=dd8b4572e0a59951cc7cf7a1120c368541554964103; expires=Fri, 10-Apr-20 06:28:23 GMT; path=/; domain=.typicode.com; HttpOnly", Server:"cloudflare", Via:"1.1 vegur", |content-encoding|:"gzip", Expires:"Wed, 01 May 2019 15:27:42 GMT", |cf-cache-status|:"HIT", |transfer-encoding|:"Identity", |cache-control|:"public, max-age=14400", |date|:"Wed, 01 May 2019 11:27:42 GMT", |access-control-allow-credentials|:"true", Connection:"keep-alive", |cf-ray|:"4d016861ac759413-NRT", Etag:"W/\"6b80-Ybsq/K6GwwqrYkAsFxqDXGC7DoM\"", Vary:"Origin, Accept-Encoding", |x-content-type-options|:"nosniff"}

on callRestGETAPIAndParseResults(reqURLStr as string, timeoutSec as integer)
  set (my retData) to false
  
set (my retCode) to 0
  
set (my retHeaders) to {}
  
set (my drecF) to false
  
  
set aURL to |NSURL|’s URLWithString:reqURLStr
  
set aRequest to NSMutableURLRequest’s requestWithURL:aURL
  
aRequest’s setHTTPMethod:"GET"
  
aRequest’s setValue:"gzip" forHTTPHeaderField:"Content-Encoding"
  
aRequest’s setValue:"application/json; charset=UTF-8" forHTTPHeaderField:"Content-Type"
  
  
set aConfig to NSURLSessionConfiguration’s defaultSessionConfiguration()
  
set aSession to NSURLSession’s sessionWithConfiguration:aConfig delegate:(me) delegateQueue:(missing value)
  
set aTask to aSession’s dataTaskWithRequest:aRequest
  
  
set hitF to false
  
aTask’s resume() –Start URL Session
  
  
repeat (1000 * timeoutSec) times
    if (my drecF) = true then
      set hitF to true
      
exit repeat
    end if
    
delay ("0.001" as real)
  end repeat
  
  
if hitF = false then error "REST API Timeout Error"
  
  
return {retData:retData, retCode:retCode, retHeaders:retHeaders}
end callRestGETAPIAndParseResults

on URLSession:tmpSession dataTask:tmpTask didReceiveData:tmpData
  parseSessionResults(tmpSession, tmpTask, tmpData) of me
  
set (my drecF) to true
end URLSession:dataTask:didReceiveData:

–ないとエラーになるので足した。とくに何もしていない
on URLSession:tmpSession dataTask:tmpTask willCacheResponse:cacheRes completionHandler:aHandler
  —
end URLSession:dataTask:willCacheResponse:completionHandler:

on parseSessionResults(aSession, aTask, tmpData)
  set aRes to aTask’s response()
  
set (my retCode) to aRes’s statusCode()
  
set (my retHeaders) to aRes’s allHeaderFields()
  
  
set resStr to NSString’s alloc()’s initWithData:tmpData encoding:(NSUTF8StringEncoding)
  
set jsonString to NSString’s stringWithString:(resStr)
  
  
set jsonData to jsonString’s dataUsingEncoding:(NSUTF8StringEncoding)
  
set aJsonDict to NSJSONSerialization’s JSONObjectWithData:jsonData options:0 |error|:(missing value)
  
  
set (my retData) to aJsonDict as list of string or string –as anything
end parseSessionResults

★Click Here to Open This Script 

Posted in REST API URL | Tagged 10.11savvy 10.12savvy 10.13savvy 10.14savvy NSJSONSerialization NSMutableURLRequest NSString NSURL NSURLSession NSURLSessionConfiguration | 3 Comments

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

Google Search

Popular posts

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

Tags

10.11savvy (1101) 10.12savvy (1242) 10.13savvy (1390) 10.14savvy (586) 10.15savvy (434) 11.0savvy (277) 12.0savvy (185) 13.0savvy (55) CotEditor (60) Finder (47) iTunes (19) Keynote (98) 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 (56) Pages (37) 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