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

カテゴリー: sdef

choose fileで指定したsdefを読み込み、sdef中のサンプル(用例)を個別にHTML書き出しする

Posted on 12月 30, 2024 by Takaaki Naganoya

スクリプトエディタから書き出したsdefファイルを選択すると、指定の書き出し先フォルダにsdef内のAppleScriptサンプルをHTML形式で書き出すAppleScriptです(最初のバージョンでHTMLの実体参照デコード処理をハードコーディングしていたのを、Cocoaの機能を利用するよう書き換えました)。

スクリプトエディタでAppleScript用語辞書を表示させた状態で、ファイル書き出しすると個別のsdefファイルとして保存できます。この状態のsdefにアプリのバージョン番号を付加して、バージョン履歴として保存しています。

こうして保存しておいたsdef内のサンプルAppleScriptをHTMLとして書き出します。Pixelmator Proに58本のサンプルScriptが入っていたので、けっこうな分量になります。それを手作業で取り出すのは手間なので、Scriptで取り出すことにしました。

それを収集するために作ったのが本Scriptです。

本来、スクリプトエディタで表示(xinclude解消+レンダリング)させたsdefを処理させるAppleScriptで、いちいちxincludeの展開を行わせるのは無意味なのですが、本Scriptはもともと「アプリのBundle IDを指定してsdefのパスを求めて処理する」ようになっていたため、仕様がとがりすぎて汎用性がいまひとつだったので、「スクリプトエディタで書き出したsdefを処理」するように書き換えたという経緯があるためです。説明したら余計にわからなくなったような、、、、

AppleScript名:choose fileで指定したsdefを読み込み、sdef中のサンプル(用例)を個別にHTML書き出しする v2.scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2024/12/31
—
–  Copyright © 2022-2024 Piyomaru Software, All Rights Reserved
—

use AppleScript
use framework "Foundation"
use framework "AppKit"
use scripting additions

set sdefAlias to (choose file of type {"com.apple.scripting-definition"} with prompt "書き出したSDEFを選択")
set sdefFullPath to (POSIX path of sdefAlias)

–SDEF読み込み(Xincludeの展開が必要な状態)
tell current application
  set theXML to read sdefAlias as «class utf8»
end tell

–NSXMLDocumentの生成、Xincludeを有効に
set {theXMLDoc, theError} to current application’s NSXMLDocument’s alloc()’s initWithXMLString:theXML options:(current application’s NSXMLDocumentXInclude) |error|:(reference)

set aDocStr to (theXMLDoc’s XMLData)
set aDocStr2 to (current application’s NSString’s alloc()’s initWithData:(aDocStr) encoding:(current application’s NSUTF8StringEncoding)) as string

set sampleList to (extractStrFromTo(aDocStr2, "<html>", "</html>") of me)
set sampleCount to length of sampleList
if sampleCount = 0 then return

set outFol to POSIX path of (choose folder with prompt "Select Output Folder")

set aCount to 1

repeat with i in sampleList
  set j to (contents of i)
  
  
if j is not equal to "" then
    set j1 to decodeCharacterReference(j) of me
    
set j2 to "<!DOCTYPE html><html><meta charset=utf-8><title>" & (aCount as string) & "</title><body>" & j1 & "</body></html>"
    
    
set wPath to outFol & (aCount as string) & ".html"
    
set fRes to writeToFileAsUTF8(j2, wPath) of me
    
if fRes = false then error
    
    
set aCount to aCount + 1
  end if
end repeat

–指定パスからアプリケーションのScriptabilityをbooleanで返す
on retAppSdefNameFromBundleIPath(appPath as string)
  set aDict to (current application’s NSBundle’s bundleWithPath:appPath)’s infoDictionary()
  
set aRes to aDict’s valueForKey:"OSAScriptingDefinition"
  
if aRes = missing value then return false
  
set asRes to aRes as string
  
  
return asRes as string
end retAppSdefNameFromBundleIPath

–指定文字と終了文字に囲まれた内容を抽出
on extractStrFromTo(aParamStr, fromStr, toStr)
  set theScanner to current application’s NSScanner’s scannerWithString:aParamStr
  
set anArray to current application’s NSMutableArray’s array()
  
  
repeat until (theScanner’s isAtEnd as boolean)
    set {theResult, theKey} to theScanner’s scanUpToString:fromStr intoString:(reference)
    
theScanner’s scanString:fromStr intoString:(missing value)
    
set {theResult, theValue} to theScanner’s scanUpToString:toStr intoString:(reference)
    
if theValue is missing value then set theValue to "" –>追加
    
theScanner’s scanString:toStr intoString:(missing value)
    
anArray’s addObject:theValue
  end repeat
  
  
return (anArray as list)
end extractStrFromTo

on writeToFileAsUTF8(aStr, aPath)
  set cStr to current application’s NSString’s stringWithString:aStr
  
set thePath to POSIX path of aPath
  
set aRes to cStr’s writeToFile:thePath atomically:false encoding:(current application’s NSUTF8StringEncoding) |error|:(missing value)
  
return aRes as boolean
end writeToFileAsUTF8

–文字置換
on repChar(origText as string, targStr as string, repStr as string)
  set {txdl, AppleScript’s text item delimiters} to {AppleScript’s text item delimiters, targStr}
  
set temp to text items of origText
  
set AppleScript’s text item delimiters to repStr
  
set res to temp as text
  
set AppleScript’s text item delimiters to txdl
  
return res
end repChar

–実体参照をデコード
on decodeCharacterReference(aStr)
  set anNSString to current application’s NSString’s stringWithString:aStr
  
set theData to anNSString’s dataUsingEncoding:(current application’s NSUTF16StringEncoding)
  
set styledString to current application’s NSAttributedString’s alloc()’s initWithHTML:theData documentAttributes:(missing value)
  
set plainText to (styledString’s |string|()) as string
  
return plainText
end decodeCharacterReference

★Click Here to Open This Script 

Posted in file File path sdef XML | Tagged 13.0savvy 14.0savvy 15.0savvy | Leave a comment

macOS 15:スクリプトエディタのAppleScript用語辞書を確認できない

Posted on 10月 25, 2024 by Takaaki Naganoya

macOS 15になって、起動中のアプリ自身が自分のバンドル内のリソースにファイルアクセスできなくなったためか(仮説)、スクリプトエディタで自身のAppleScript用語辞書を確認できていません(macOS 15.1)。

用語辞書を読まずにAppleScriptを書くことはできないので、従来のmacOS 13や14から比べると「困った改変」です。

一応、Script Debuggerを用いてスクリプトエディタのAppleScript用語辞書をブラウズすることは可能であるため、不可能になったわけではないのですが、スクリプトエディタで用語辞書をオープンできないと、辞書内容をファイル保存して、変更点の差分を検出できなくて(私が)困っています。

スクリプトエディタのAppleScript用語辞書は、バンドル内にsdefの形式で格納されなくなったため(.scriptsuites書類?)バンドルの中身を開けてコピーというFinderのような解決策をとることができません。

Posted in Bug sdef | Tagged 15.0savvy Script Editor | 2 Comments

指定のSDEFファイルからコマンドを抽出

Posted on 10月 17, 2024 by Takaaki Naganoya

アプリからスクリプトエディタを用いて書き出したSDEFファイル(AppleScript用語説明ファイル)から、コマンドを抽出するAppleScriptです。

–> Download sdef command lister.scptd (Including AS Lib in its bundle)

個人的に、SDEFの差分を確認するために極力アプリの各バージョンのSDEFを書き出して保存するようにしており、

用語辞書ベースで機能追加や変更が行われたことを確認しています。


▲Skim v1.0のAppleScript用語辞書


▲Skim v1.7.5のAppleScript用語辞書

こうしたSDEFのままでは比較できないので、FileMerge(XcodeについてくるGUI版diffの傑作)を使ってバージョン間の差分を取って確認するのが「通常営業」なわけです。

これがv1.0から最新版までの経緯をおおまかに把握したい、といったときには細かすぎますし、用途に合っていません。

そこで本Scriptを書いて利用することにしました。各バージョンごとにコマンドを抽出して、存在する/しないといった比較ができれば全体的な傾向を把握できます。

Apple純正アプリのSDEF、Adobe Creative Cloudアプリ、Microsoft OfficeのSDEFなどひととおり処理してみましたが、自分が使った範囲ではとくに問題は見つかっていません。ただ、まだ間違いがあるかもしれないため、処理ミスが見られた場合にはコメントで報告してください。


▲本Scriptを用いて、Skim各バージョンのAppleScript用語辞書からコマンドの分布を表にしたもの

AppleScript名:指定のSDEFファイルからコマンドを抽出.scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2024/10/16
—
–  Copyright © 2022-2024 Piyomaru Software, All Rights Reserved
—

use AppleScript version "2.4" — Yosemite (10.10) or later
use framework "Foundation"
use framework "AppKit"
use xmlLib : script "piyoXML"
use scripting additions

script myDict
  property sdefDict : {}
end script

set sdefPath to (POSIX path of (choose file of type {"com.apple.scripting-definition"} with prompt "SDEFファイルを選択"))

set comRes to {}

set (sdefDict of myDict) to {}
set comList to parseSdefAndRetObjects(sdefPath) of me

repeat with i in comList
  set j to contents of i
  
set aRes to parseSdefFileAndRetCommandStructure(sdefPath, j) of me
  
if aRes is not equal to "" then set aRes to "OK"
  
set the end of comRes to j
end repeat

set aStr to listToStringUsingTextItemDelimiter(comRes, return) of me

on parseSdefFileAndRetCommandStructure(targSDEFPath, aTargCom)
  set suitesList to ((sdefDict of myDict)’s valueForKeyPath:"dictionary.suite.command")
  
  
repeat with i in suitesList –SuitesでLoop
    set j to contents of i
    
    
try
      if j is not equal to missing value and j is not equal to current application’s NSNull then
        repeat with ii in j –CommandでLoop
          set jj to contents of ii
          
set tmpName to jj’s attributes’s |name|
          
          
if aTargCom is in (tmpName as list) then return jj
        end repeat
      end if
    on error
      return ""
    end try
    
  end repeat
  
return false
end parseSdefFileAndRetCommandStructure

–指定Bundle IDのコマンド一覧を取得する
on parseSdefAndRetObjects(sdefPath)
  if (sdefDict of myDict) = {} then
    set aRes to parseSDEFfileAndRetXMLStr(sdefPath) of me
    
set (sdefDict of myDict) to (xmlLib’s makeRecordWithXML:aRes)
  end if
  
  
set e1Res to (sdefDict of myDict)’s valueForKeyPath:"dictionary.suite.command.attributes.name"
  
  
set fRes to FlattenList(e1Res as list) of me
  
set bList to cleanUp1DList(fRes, {"missing value"}) of me
  
set gRes to uniquify1DList(bList, true) of me
  
return gRes
end parseSdefAndRetObjects

–SDEFをXincludeを考慮しつつ展開
on parseSDEFfileAndRetXMLStr(sdefFullPath)
  set sdefAlias to (POSIX file sdefFullPath) as alias –sdefのフルパスを求める
  
  
–SDEF読み込み(Xincludeの展開が必要な状態)
  
tell current application
    set theXML to read sdefAlias as «class utf8»
  end tell
  
  
–NSXMLDocumentの生成、Xincludeを有効に
  
set {theXMLDoc, theError} to current application’s NSXMLDocument’s alloc()’s initWithXMLString:theXML options:(current application’s NSXMLDocumentXInclude) |error|:(reference)
  
  
–XMLを文字データ化
  
set aDocStr to (theXMLDoc’s XMLData)
  
set aDocStr2 to (current application’s NSString’s alloc()’s initWithData:(aDocStr) encoding:(current application’s NSUTF8StringEncoding)) as string
  
  
return aDocStr2
end parseSDEFfileAndRetXMLStr

–By Paul Berkowitz
–2009年1月27日 2:24:08:JST
–Re: Flattening Nested Lists
on FlattenList(aList)
  set oldDelims to AppleScript’s text item delimiters
  
set AppleScript’s text item delimiters to {"????"}
  
set aString to aList as text
  
set aList to text items of aString
  
set AppleScript’s text item delimiters to oldDelims
  
return aList
end FlattenList

on cleanUp1DList(aList as list, cleanUpItems as list)
  set bList to {}
  
repeat with i in aList
    set j to contents of i
    
if j is not in cleanUpItems then
      set the end of bList to j
    end if
  end repeat
  
return bList
end cleanUp1DList

–1D/2D Listをユニーク化
on uniquify1DList(theList as list, aBool as boolean)
  set aArray to current application’s NSArray’s arrayWithArray:theList
  
set bArray to aArray’s valueForKeyPath:"@distinctUnionOfObjects.self"
  
if aBool = true then
    return bArray as list
  else
    return bArray
  end if
end uniquify1DList

–1D Listを指定デリミタをはさんでテキスト化(Shane Stanley)
on listToStringUsingTextItemDelimiter(sourceList, textItemDelimiter)
  set CocoaArray to current application’s NSArray’s arrayWithArray:sourceList
  
set CocoaString to CocoaArray’s componentsJoinedByString:textItemDelimiter
  
return (CocoaString as string)
end listToStringUsingTextItemDelimiter

★Click Here to Open This Script 

Posted in sdef XML | 1 Comment

指定Bundle IDのアプリのsdefを指定フォルダに取り出す

Posted on 6月 27, 2024 by Takaaki Naganoya

新しいOSのベータ版や、古いOS環境のAppleScript用語辞書をまとめて取り出すために作成したAppleScriptです。

アプリケーションのバンドル内から直接sdefを取り出すと、他の要素を外部からincludeしているsdefでは「完全体」にならない(資料として価値がなくなる)ため、Script Editorで表示(レンダリング)させた状態のものをコピーするよう処理しています。

以前にもこうした種類のScriptを書いていたような気もするのですが、どこかに行ってしまいました。

macOSのバージョン、ビルドNo.などを取得し、コピーしたSDEFファイルに対象アプリのバージョン番号ともども記載するようにしています。

本Scriptはスクリプトエディタを操作するものであるため、Script Debuggerなどの他の実行プログラムから実行することが望ましいところです。

そして、macOS 15.0beta2でもScript Debuggerが起動しないため、肝心のmacOS 15Betaでsdef書き出しを自動化できていないという………

AppleScript名:指定Bundle IDのアプリのsdefを指定フォルダに取り出す.scpt
—
–  Created by: Takaaki Naganoya
–  Created on: 2024/06/27
—
–  Copyright © 2024 Piyomaru Software, All Rights Reserved
—
use AppleScript
use scripting additions
use framework "Foundation"
use framework "AppKit"

set aList to {"com.apple.iCal", "com.apple.AddressBook", "com.apple.databaseevents", "com.apple.finder", "com.apple.imageevents", "com.apple.mail", "com.apple.MobileSMS", "com.apple.Music", "com.apple.Notes", "com.apple.Photos", "com.apple.QuickTimePlayerX", "com.apple.reminders", "com.apple.Safari", "com.apple.ScriptEditor2", "com.apple.speech.SpeechRecognitionServer", "com.apple.systemevents", "com.apple.Terminal", "com.apple.TextEdit", "com.apple.TV", "com.apple.systempreferences"}

set targFol to POSIX path of (choose folder with prompt "SDEF収集先フォルダを選択")

–Get OS Version and Build Number
set sDic to current application’s NSDictionary’s dictionaryWithContentsOfFile:"/System/Library/CoreServices/SystemVersion.plist"
set osV to (sDic’s objectForKey:"ProductVersion") as string
set bNo to (sDic’s objectForKey:"ProductBuildVersion") as string

–Loop by Bundle IDs
repeat with i in aList
  set j to contents of i
  
set aRes to retPathFromBundleID(j) of me
  
set appAlias to (POSIX file aRes) as alias
  
  
set vRes to gepAppVersionByID(j) of me
  
  
tell application "Script Editor"
    open appAlias –Open App –> SDEF will be displayed
    
    
tell front document
      set docPath to path of it
    end tell
  end tell
  
  
do shell script "sync" –Important!!!!
  
  
set aP1 to (current application’s NSString’s stringWithString:(docPath as string))
  
set theName to aP1’s lastPathComponent()
  
set aP2 to (current application’s NSString’s stringWithString:targFol)
  
set newPath to (aP2’s stringByAppendingPathComponent:theName)
  
set aExt to (newPath’s pathExtension()) as string
  
set newPath to (newPath’s stringByDeletingPathExtension() as string) & "_v" & vRes & "@" & osV & "(" & bNo & ")." & aExt
  
  
–Copy SDEF file
  
set aRes to (my copyFileAt:aP1 toFilePath:newPath)
  
  
–Close SDEF
  
tell application "Script Editor"
    tell front document
      close without saving
    end tell
  end tell
  
end repeat

–バンドルIDからApp Fileのパスを求める
on retPathFromBundleID(aBundleID)
  set aURL to current application’s NSWorkspace’s sharedWorkspace()’s URLForApplicationWithBundleIdentifier:aBundleID
  
if aURL = missing value then return false –Error
  
return aURL’s |path|() as string
end retPathFromBundleID

–ファイルのコピー
on copyFileAt:origPOSIXPath toFilePath:newPOSIXPath
  set POSIXPath1 to current application’s NSString’s stringWithString:origPOSIXPath
  
set POSIXPath2 to current application’s NSString’s stringWithString:newPOSIXPath
  
set fileManager to current application’s NSFileManager’s defaultManager()
  
set theResult to fileManager’s copyItemAtPath:POSIXPath1 toPath:POSIXPath2 |error|:(missing value)
  
return (theResult as integer = 1)
end copyFileAt:toFilePath:

–バンドルIDで指定したアプリケーションのバージョン番号を文字列で取得する
on gepAppVersionByID(aBundleID)
  
  
set aURL to current application’s NSWorkspace’s sharedWorkspace()’s URLForApplicationWithBundleIdentifier:aBundleID
  
set theResult to {}
  
  
set theNSBundle to (current application’s NSBundle’s bundleWithURL:aURL)
  
  
if aURL is not missing value then
    set theVersionString to ((theNSBundle’s infoDictionary())’s objectForKey:"CFBundleShortVersionString")
    
    
if theVersionString is not missing value then
      return theVersionString as string
    end if
    
  end if
  
  
return ""
end gepAppVersionByID

★Click Here to Open This Script 

Posted in file sdef | Tagged 13.0savvy 14.0savvy 15.0savvy Script Editor | Leave a comment

Safari v16がリリースされる

Posted on 9月 14, 2022 by Takaaki Naganoya

Safari v16がリリースされました。AppleScript用語辞書的には、v15.6.1からとくに変更はありません。

ただし、v15.0.4から比べると、AppleScript用語辞書のサイズが半分に。よくよく調べてみると、v15.6.1のあたりでStandard Suitesの定義をxincludeで外部から参照するように変更されていました。

また、v15.6.1からはSafariのAppleScript用語辞書はきちんと清書されて改行が削除されない状態で入れられるようになったようです。

AppleScript用語辞書の改行削除は、Adobe InDesignやIllustratorあたりで見かけた小技で、改行コードを削除した分、当時のCPUで苦労していた辞書のParse処理負荷を軽減することを目的としていたようです。

ただ、その内容をどうやってメンテナンスしているのかは疑問で、もともとの改行が入ったAppleScript用語辞書が維持されていなければ、どう編集してよいかわからないことでしょう。

なので、今後も用語辞書を維持・変更していくうえでは、改行コードつきのAppleScript用語辞書のままであることは重要です。

とはいえ、Safari v16はAppleScript的には何も新しい機能はありません。

Posted in sdef | Tagged 12.0savvy Safari | Leave a comment

Bundle IDで指定したアプリケーションのSDEFからコマンドを抽出テスト(指定コマンドのコマンド属性取り出し)

Posted on 8月 13, 2022 by Takaaki Naganoya

アプリケーションのSDEF(AppleScript用語辞書)を解析して情報を取り出すシリーズの本命。指定コマンドの属性値を取り出すテスト用のAppleScriptです。

–> Download script with library

まだ、明確な成果が出ているわけではありませんが、こうしてアクセスして問題がないか、多くのアプリケーションの各コマンドで問題がないかを調査しているところです。

AppleScript名:Bundle IDで指定したアプリケーションのSDEFからコマンドを抽出テスト(指定コマンドのコマンド属性取り出し).scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2022/08/2
—
–  Copyright © 2022 Piyomaru Software, All Rights Reserved
—

use AppleScript version "2.4" — Yosemite (10.10) or later
use framework "Foundation"
use framework "AppKit"
use xmlLib : script "piyoXML"
use scripting additions

script myDict
  property sdefDict : {}
end script

set (sdefDict of myDict) to {}
set aRes to parseSdefAndRetCommandStructure("com.apple.iWork.Keynote", "export") of me

on parseSdefAndRetCommandStructure(targAppBundleID, aTargCom)
  if (sdefDict of myDict) = {} then
    set aRes to parseSDEFandRetXMLStr(targAppBundleID) of me
    
set (sdefDict of myDict) to (xmlLib’s makeRecordWithXML:aRes)
  end if
  
  
set suitesList to ((sdefDict of myDict)’s valueForKeyPath:"dictionary.suite.command")
  
  
repeat with i in suitesList –SuitesでLoop
    set j to contents of i
    
    
try
      repeat with ii in j –CommandでLoop
        set jj to contents of ii
        
set tmpName to jj’s attributes’s |name|
        
        
if aTargCom is in (tmpName as list) then return jj
        
      end repeat
    on error
      return false
    end try
    
  end repeat
  
return false
end parseSdefAndRetCommandStructure

on pickUpFromToStr(aStr as string, s1Str as string, s2Str as string)
  set a1Offset to offset of s1Str in aStr
  
if a1Offset = 0 then return -1
  
set bStr to text (a1Offset + (length of s1Str)) thru -1 of aStr
  
  
set a2Offset to offset of s2Str in bStr
  
if a2Offset = 0 then return -2
  
  
set cStr to text 1 thru (a2Offset – (length of s2Str)) of bStr
  
  
return cStr as string
end pickUpFromToStr

–指定文字と終了文字に囲まれた内容を抽出
on extractStrFromTo(aParamStr, fromStr, toStr)
  set theScanner to current application’s NSScanner’s scannerWithString:aParamStr
  
set anArray to current application’s NSMutableArray’s array()
  
  
repeat until (theScanner’s isAtEnd as boolean)
    set {theResult, theKey} to theScanner’s scanUpToString:fromStr intoString:(reference)
    
theScanner’s scanString:fromStr intoString:(missing value)
    
set {theResult, theValue} to theScanner’s scanUpToString:toStr intoString:(reference)
    
if theValue is missing value then set theValue to "" –>追加
    
theScanner’s scanString:toStr intoString:(missing value)
    
anArray’s addObject:theValue
  end repeat
  
  
if anArray’s |count|() is not equal to 1 then return false
  
  
return first item of (anArray as list)
end extractStrFromTo

–SDEFをXincludeを考慮しつつ展開
on parseSDEFandRetXMLStr(targAppBundleID)
  set thePath to POSIX path of (path to application id targAppBundleID)
  
  
set aSDEFname to retAppSdefNameFromBundleIPath(thePath, "OSAScriptingDefinition") of me
  
if aSDEFname = false then return
  
  
if aSDEFname does not end with ".sdef" then set aSDEFname to aSDEFname & ".sdef"
  
set sdefFullPath to thePath & "Contents/Resources/" & aSDEFname
  
set sdefAlias to (POSIX file sdefFullPath) as alias –sdefのフルパスを求める
  
  
–SDEF読み込み(Xincludeの展開が必要な状態)
  
tell current application
    set theXML to read sdefAlias as «class utf8»
  end tell
  
  
–NSXMLDocumentの生成、Xincludeを有効に
  
set {theXMLDoc, theError} to current application’s NSXMLDocument’s alloc()’s initWithXMLString:theXML options:(current application’s NSXMLDocumentXInclude) |error|:(reference)
  
  
–XMLを文字データ化
  
set aDocStr to (theXMLDoc’s XMLData)
  
set aDocStr2 to (current application’s NSString’s alloc()’s initWithData:(aDocStr) encoding:(current application’s NSUTF8StringEncoding)) as string
  
  
return aDocStr2
end parseSDEFandRetXMLStr

–指定パスからアプリケーションのInfo.plist中の属性値を返す
on retAppSdefNameFromBundleIPath(appPath as string, aKey as string)
  set aDict to (current application’s NSBundle’s bundleWithPath:appPath)’s infoDictionary()
  
set aRes to aDict’s valueForKey:(aKey)
  
if aRes = missing value then return false
  
set asRes to aRes as string
  
  
return asRes as string
end retAppSdefNameFromBundleIPath

★Click Here to Open This Script 

Posted in sdef System XML | Tagged 10.14savvy 10.15savvy 11.0savvy 12.0savvy | Leave a comment

Bundle IDで指定したアプリケーションのSDEF内容を表示(OSADictionary)

Posted on 8月 9, 2022 by Takaaki Naganoya

指定のBundle IDのアプリケーションのAppleScript用語辞書(sdef)から、Xincludeを解消して、外部参照していた内容を展開してHTMLに変換してWkWebViewで表示するAppleScriptです。

–> dispAppScriptDict.scptd(Bundle Script with Script Library in its bundle)

AppleScript用語辞書シリーズで、sdefの外部参照をXML系のサービスを利用して展開していましたが、OSAKitのOSADictionaryで展開できるという噂を聞きつけ、調査して試してみました。

参照した情報は、こちらのページです。

XML系のOSの機能を利用したときには発生していなかった現象ですが、Bundle IDで指定したアプリケーションが本Script実行時に起動されました。

Adobe系のアプリケーションは未検証ですが、本ScriptでAdobe系アプリケーション(InDesign、Illustrator、Photoshop)の用語辞書を、スクリプトエディタに近い状態で表示できれば、辞書の展開も大丈夫というところでしょうか。

# 辞書内容をHTMLではなくXMLとして取得したら、Xincludeは展開されていなかったので、このやり方ではダメということなんでしょう>辞書部品の外部参照の解消
# OSAKit.frameworkそのものをFinder上でこじ開けてみると、cssとxsltが存在していることがわかるので、このあたりの手順で辞書の展開を行っているようなのですが、、、

本来自分がやりたいのは、こんな用語辞書の表示ではないので、とりあえず「試してみた」というところでしょうか。

AppleScript名:Bundle IDで指定したアプリケーションのSDEFからXPathで指定したClassにアクセス(OSADictionary).scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2022/08/09
—
–  Copyright © 2022 Piyomaru Software, All Rights Reserved
—

use AppleScript version "2.4" — Yosemite (10.10) or later
use framework "Foundation"
use framework "AppKit"
use framework "OSAKit"
use webD : script "webDialogLib"
use scripting additions

set targAppBundleID to "com.apple.iWork.Keynote" –SDEFを取り出すターゲットのアプリケーションのBundle ID

set thePath to POSIX path of (path to application id targAppBundleID)

set aSDEFname to retAppSdefNameFromBundleIPath(thePath, "OSAScriptingDefinition") of me
if aSDEFname = false then return

if aSDEFname does not end with ".sdef" then set aSDEFname to aSDEFname & ".sdef"
set sdefFullPath to thePath & "Contents/Resources/" & aSDEFname

–https://github.com/LeoNatan/Apple-Runtime-Headers/blob/
–5e50ad05dfd7d7b69fc2e0e685765fc054166b3c/macOS/Frameworks/OSAKit.framework/OSADictionary.h
set aDict to current application’s OSADictionary’s alloc()’s initWithContentsOfFile:sdefFullPath |error|:(missing value)
if aDict = missing value then return

aDict’s parse()
set aHTML to aDict’s html() as string

set paramObj to {myMessage:"AppleScript用語辞書の表示テスト", mySubMessage:"OSADictionaryで読み込んだsdefをHML化してWkWebViewで表示", htmlStr:aHTML, htmlPath:"", jsDelimiters:{"", ""}, viewSize:{600, 400}}

–webD’s browseStrWebContents:paramObj –for debug
webD’s displayWebDialog(paramObj)

–指定パスからアプリケーションのInfo.plist中の属性値を返す
on retAppSdefNameFromBundleIPath(appPath as string, aKey as string)
  set aDict to (current application’s NSBundle’s bundleWithPath:appPath)’s infoDictionary()
  
set aRes to aDict’s valueForKey:(aKey)
  
if aRes = missing value then return false
  
set asRes to aRes as string
  
  
return asRes as string
end retAppSdefNameFromBundleIPath

★Click Here to Open This Script 

Posted in dialog OSA sdef | Tagged 10.15savvy 11.0savvy 12.0savvy | Leave a comment

Bundle IDで指定したアプリケーションのSDEFからオブジェクトを抽出

Posted on 8月 3, 2022 by Takaaki Naganoya

指定アプリケーションのSDEFを走査して、アプリケーションのAppleScript用語辞書に掲載されているオブジェクトを抽出するAppleScriptです。まだ、実験的な段階のものです。

XMLをパースするためのライブラリ(Shaneがつくったもの)を併用するため、Scriptライブラリ入りのScriptをダウンロードして実行してみてください。

–>Download Bundle Script With Script Library

ここまで試しておいてナニですが、Adobe系のアプリケーションの用語辞書については、アプリケーション上で動的に生成するようなので、Adobe系のアプリケーションに対して正しい結果を取得できることは期待しないでください。

XML的にアクセスすると、「属性値がここで取得できるはずなのだが」といった不思議な現象のオンパレードでした。edama2さんからの助言もあり、XMLをそのままではなくNSDictionaryに変換してアクセスしたのが本Scriptです。

ちょっとした試行錯誤を経て、Keynote.appのオブジェクトについては取得できている印象です。

オブジェクトを取得したら、各オブジェクトの属性値を取れるようにして、オブジェクトが応答するコマンドの一覧を取得し…というところまではいけるんじゃないでしょうか。

AppleScript名:Bundle IDで指定したアプリケーションのSDEFからオブジェクトを抽出.scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2022/08/2
—
–  Copyright © 2022 Piyomaru Software, All Rights Reserved
—

use AppleScript version "2.4" — Yosemite (10.10) or later
use framework "Foundation"
use framework "AppKit"
use xmlLib : script "piyoXML"
use scripting additions

set aRes to parseSdefAndRetObjects("com.apple.iWork.Keynote") of me
–> {"column", "text item", "application", "word", "image", "rich text", "iWork item", "window", "group", "movie", "slide layout", "line", "paragraph", "slide", "audio clip", "shape", "table", "range", "row", "cell", "theme", "iWork container", "character", "document", "chart"}

set bRes to parseSdefAndRetObjects("com.apple.iWork.Pages") of me
–> {"column", "text item", "application", "word", "image", "rich text", "iWork item", "template", "window", "group", "movie", "shape", "line", "row", "paragraph", "placeholder text", "range", "audio clip", "table", "cell", "document", "page", "iWork container", "chart", "character", "section"}

set cRes to parseSdefAndRetObjects("com.apple.iWork.Numbers") of me
–> {"column", "text item", "application", "word", "image", "rich text", "iWork item", "template", "window", "group", "movie", "shape", "line", "paragraph", "row", "audio clip", "range", "table", "cell", "iWork container", "document", "character", "chart", "sheet"}

set dRes to parseSdefAndRetObjects("com.apple.Finder") of me
–> {"container", "application", "alias list", "list view options", "alias file", "item", "document file", "preferences", "icon view options", "application process", "trash-object", "internet location file", "process", "Finder window", "desktop window", "window", "application file", "computer-object", "column view options", "clipping window", "desktop-object", "clipping", "file", "icon family", "folder", "desk accessory process", "label", "column", "preferences window", "information window", "package", "disk"}

set eRes to parseSdefAndRetObjects("com.apple.Safari") of me
–> {"document", "contentsProvider", "tab", "application", "sourceProvider", "window"}

set fRes to parseSdefAndRetObjects("com.apple.Mail") of me
–> {"account", "container", "application", "cc recipient", "mailbox", "word", "outgoing message", "rich text", "smtp server", "attachment", "bcc recipient", "pop account", "window", "signature", "to recipient", "OLD message editor", "paragraph", "iCloud account", "ldap server", "recipient", "message", "rule condition", "header", "document", "attribute run", "rule", "imap account", "mail attachment", "message viewer", "character"}

set gRes to parseSdefAndRetObjects("com.coteditor.CotEditor") of me
–> {"window", "paragraph", "word", "character", "attribute run", "document", "text selection", "rich text", "application", "attachment"}

set hRes to parseSdefAndRetObjects("com.pixelmatorteam.pixelmator.x") of me
–> {"vortex effect", "paragraph", "focus effect", "bump effect", "layer", "color adjustments", "box effect", "stripes effect", "window", "circle splash effect", "document info", "word", "text layer", "tilt shift effect", "image fill effect", "disc effect", "gaussian effect", "color fill effect", "effects layer", "ellipse shape layer", "styles", "motion effect", "rich text", "pattern fill effect", "spin effect", "line shape layer", "application", "light tunnel effect", "image layer", "group layer", "character", "rounded rectangle shape layer", "crystallize effect", "shape layer", "star shape layer", "pinch effect", "checkerboard effect", "effect", "rectangle shape layer", "pixelate effect", "pointillize effect", "document", "hole effect", "twirl effect", "polygon shape layer", "zoom effect", "color adjustments layer"}

on parseSdefAndRetObjects(targAppBundleID)
  set aRes to parseSDEFandRetXMLStr(targAppBundleID) of me
  
set cRes to (xmlLib’s makeRecordWithXML:aRes)
  
  
–2つのタイプのオブジェクトがある? まだある???
  
set e1Res to cRes’s valueForKeyPath:"dictionary.suite.class.element.attributes.type"
  
set e2Res to cRes’s valueForKeyPath:"dictionary.suite.class.attributes.name"
  
set eRes to (e1Res as list) & (e2Res as list)
  
  
set fRes to FlattenList(eRes) of me
  
set bList to cleanUp1DList(fRes, {"missing value"}) of me
  
set gRes to uniquify1DList(bList, true) of me
  
set hRes to uniquify1DList(gRes, true) of me
  
return hRes
end parseSdefAndRetObjects

on pickUpFromToStr(aStr as string, s1Str as string, s2Str as string)
  set a1Offset to offset of s1Str in aStr
  
if a1Offset = 0 then return -1
  
set bStr to text (a1Offset + (length of s1Str)) thru -1 of aStr
  
  
set a2Offset to offset of s2Str in bStr
  
if a2Offset = 0 then return -2
  
  
set cStr to text 1 thru (a2Offset – (length of s2Str)) of bStr
  
  
return cStr as string
end pickUpFromToStr

–指定文字と終了文字に囲まれた内容を抽出
on extractStrFromTo(aParamStr, fromStr, toStr)
  set theScanner to current application’s NSScanner’s scannerWithString:aParamStr
  
set anArray to current application’s NSMutableArray’s array()
  
  
repeat until (theScanner’s isAtEnd as boolean)
    set {theResult, theKey} to theScanner’s scanUpToString:fromStr intoString:(reference)
    
theScanner’s scanString:fromStr intoString:(missing value)
    
set {theResult, theValue} to theScanner’s scanUpToString:toStr intoString:(reference)
    
if theValue is missing value then set theValue to "" –>追加
    
theScanner’s scanString:toStr intoString:(missing value)
    
anArray’s addObject:theValue
  end repeat
  
  
if anArray’s |count|() is not equal to 1 then return false
  
  
return first item of (anArray as list)
end extractStrFromTo

–SDEFをXincludeを考慮しつつ展開
on parseSDEFandRetXMLStr(targAppBundleID)
  set thePath to POSIX path of (path to application id targAppBundleID)
  
  
set aSDEFname to retAppSdefNameFromBundleIPath(thePath, "OSAScriptingDefinition") of me
  
if aSDEFname = false then return
  
  
if aSDEFname does not end with ".sdef" then set aSDEFname to aSDEFname & ".sdef"
  
set sdefFullPath to thePath & "Contents/Resources/" & aSDEFname
  
set sdefAlias to (POSIX file sdefFullPath) as alias –sdefのフルパスを求める
  
  
–SDEF読み込み(Xincludeの展開が必要な状態)
  
tell current application
    set theXML to read sdefAlias as «class utf8»
  end tell
  
  
–NSXMLDocumentの生成、Xincludeを有効に
  
set {theXMLDoc, theError} to current application’s NSXMLDocument’s alloc()’s initWithXMLString:theXML options:(current application’s NSXMLDocumentXInclude) |error|:(reference)
  
  
–XMLを文字データ化
  
set aDocStr to (theXMLDoc’s XMLData)
  
set aDocStr2 to (current application’s NSString’s alloc()’s initWithData:(aDocStr) encoding:(current application’s NSUTF8StringEncoding)) as string
  
  
return aDocStr2
end parseSDEFandRetXMLStr

–指定パスからアプリケーションのInfo.plist中の属性値を返す
on retAppSdefNameFromBundleIPath(appPath as string, aKey as string)
  set aDict to (current application’s NSBundle’s bundleWithPath:appPath)’s infoDictionary()
  
set aRes to aDict’s valueForKey:(aKey)
  
if aRes = missing value then return false
  
set asRes to aRes as string
  
  
return asRes as string
end retAppSdefNameFromBundleIPath

–By Paul Berkowitz
–2009年1月27日 2:24:08:JST
–Re: Flattening Nested Lists
on FlattenList(aList)
  set oldDelims to AppleScript’s text item delimiters
  
set AppleScript’s text item delimiters to {"????"}
  
set aString to aList as text
  
set aList to text items of aString
  
set AppleScript’s text item delimiters to oldDelims
  
return aList
end FlattenList

on cleanUp1DList(aList as list, cleanUpItems as list)
  set bList to {}
  
repeat with i in aList
    set j to contents of i
    
if j is not in cleanUpItems then
      set the end of bList to j
    end if
  end repeat
  
return bList
end cleanUp1DList

–1D/2D Listをユニーク化
on uniquify1DList(theList as list, aBool as boolean)
  set aArray to current application’s NSArray’s arrayWithArray:theList
  
set bArray to aArray’s valueForKeyPath:"@distinctUnionOfObjects.self"
  
if aBool = true then
    return bArray as list
  else
    return bArray
  end if
end uniquify1DList

★Click Here to Open This Script 

Posted in sdef XML | Tagged 11.0savvy 12.0savvy | Leave a comment

Bundle IDで指定したアプリケーションのSDEFからXPathで指定したClassにアクセス v2

Posted on 8月 2, 2022 by Takaaki Naganoya

Bundle IDで指定したアプリケーションのSDEF(AppleScript定義辞書)を、Xincludeを考慮しつつparseして、XPathで指定したクラスにアクセスするAppleScriptです。

KeynoteのAppleScript用語辞書の「open」コマンド、

を指定して本Scriptでデータを取り出すと、

のような出力が得られます。まだちょっと、属性値を取り出すところまで行っていませんが、つまり…指定コマンドのパラメータや、指定クラスがどのようなコマンドに応答するかなど、プログラム側からわかるようになることでしょう(多分)。

AppleScript名:Bundle IDで指定したアプリケーションのSDEFからXPathで指定したClassにアクセス v2.scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2022/08/2
—
–  Copyright © 2022 Piyomaru Software, All Rights Reserved
—

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

set targAppBundleID to "com.apple.iWork.Keynote" –SDEFを取り出すターゲットのアプリケーションのBundle ID
–set commandXPath to "//class[@name=’application’]/property"
–set commandXPath to "//command[@name=’open’]/direct-parameter"
–set commandXPath to "//class[@name=’document’]/property"
–set commandXPath to "//class[@name=’document’]/responds-to"
–set commandXPath to "//command[@name=’open’]" –Open Command–Open コマンド
set commandXPath to "//command[@name=’open’]/direct-parameter/type" –Open Command–Open コマンド

set aRes to parseSDEFandRetXPathData(targAppBundleID, commandXPath) of me
return aRes

–SDEFをXincludeを考慮しつつ展開
on parseSDEFandRetXPathData(targAppBundleID, commandXPath)
  set thePath to POSIX path of (path to application id targAppBundleID)
  
  
set aSDEFname to retAppSdefNameFromBundleIPath(thePath, "OSAScriptingDefinition") of me
  
if aSDEFname = false then return
  
  
if aSDEFname does not end with ".sdef" then set aSDEFname to aSDEFname & ".sdef"
  
set sdefFullPath to thePath & "Contents/Resources/" & aSDEFname
  
set sdefAlias to (POSIX file sdefFullPath) as alias –sdefのフルパスを求める
  
  
–SDEF読み込み(Xincludeの展開が必要な状態)
  
tell current application
    set theXML to read sdefAlias as «class utf8»
  end tell
  
  
–NSXMLDocumentの生成、Xincludeを有効に
  
set {theXMLDoc, theError} to current application’s NSXMLDocument’s alloc()’s initWithXMLString:theXML options:(current application’s NSXMLDocumentXInclude) |error|:(reference)
  
  
–XMLを文字データ化
  
set aDocStr to (theXMLDoc’s XMLData)
  
set aDocStr2 to (current application’s NSString’s alloc()’s initWithData:(aDocStr) encoding:(current application’s NSUTF8StringEncoding)) as string
  
  
set dRes to my extractFrom:theXMLDoc matchingXPath:commandXPath
  
return dRes
end parseSDEFandRetXPathData

–指定のNSXMLDocumentから、指定のXPathでアクセスして内容を返す
on extractFrom:theNSXMLDocument matchingXPath:theQuery
  set attStrings to {} — where attributes will be stored
  
set theXMLOutput to current application’s NSXMLElement’s alloc()’s initWithName:"output" — found nodes added to this
  
  
set {theResults, theNSError} to (theNSXMLDocument’s nodesForXPath:theQuery |error|:(reference)) — query
  
  
if theResults is not missing value then
    repeat with anNSXMLNode in (theResults as list)
      anNSXMLNode’s detach() — need to detach first
      
if anNSXMLNode’s |kind|() as integer = current application’s NSXMLAttributeKind then — see if it’s an attribute or node
        set end of attStrings to (anNSXMLNode’s stringValue()) as {text, list, record}
      else
        (theXMLOutput’s addChild:anNSXMLNode) — add node
      end if
    end repeat
    
    
return (theXMLOutput’s XMLStringWithOptions:(current application’s NSXMLNodePrettyPrint)) as {text, list, record}
  else
    return missing value
  end if
end extractFrom:matchingXPath:

–指定パスからアプリケーションのInfo.plist中の属性値を返す
on retAppSdefNameFromBundleIPath(appPath as string, aKey as string)
  set aDict to (current application’s NSBundle’s bundleWithPath:appPath)’s infoDictionary()
  
set aRes to aDict’s valueForKey:(aKey)
  
if aRes = missing value then return false
  
set asRes to aRes as string
  
  
return asRes as string
end retAppSdefNameFromBundleIPath

★Click Here to Open This Script 

Posted in sdef System XML | Tagged 10.15savvy 11.0savvy 12.0savvy Keynote | 1 Comment

xincludeを有効にしてXML(sdef)読み込み v2

Posted on 7月 26, 2022 by Takaaki Naganoya

指定のBundle IDのアプリケーションのInfo.plistの値からSDEF(AppleScript命令定義ファイル)のファイル情報を読み取って、実際にSDEFの実ファイルを読み取り、得られた文字列をXMLとして解釈する際にXincludeを展開して、再度文字列に戻すAppleScriptです。

もともと、SDEFを読み取って分析することは、アプリケーションのバージョン間の変更差分を検出する用途で試していました。これは、変化のみを検出することを目的としたもので、内容について仔細に認識することを目的としたものではありませんでした。

そこから1歩進んで、AppleScript側から実行環境情報を取得する試みをいろいろ続けてきました。

実行環境自体が何なのか、という判別はここ数年で一番大きな成果だったと感じます。地球にいながら「銀河系の中の、太陽系の中の第3惑星にいる」ということが観測できるようになったわけです。

さらに、それぞれのランタイム環境の識別が可能になったことにより、各実行環境の「差」を判定しやすくなった、という副産物もありました。

話を戻しましょう。

SDEFを読んで、当該アプリケーションが何を行えるかをAppleScript側からも認識できるはずで、そのための調査も開始していました。

System Eventsの「Scripting Definition Suite」はその名前と用語から、AppleScriptからSDEFの解析を行うための部品であることが推測され、いろいろ調べてきたものの…..Apple側がSystem Eventsそれ自体のチェックを行うために設けた「メンテナンス&デバッグのための機能(ただしSystem Events専用)」だという結論にいたっています。つまり、System Events以外にはまるっきり使えません。

これで、AppleScriptのプログラム側からアプリケーション側の仕様を自動判別&解析するためには、SDEFそのものを解析するしかないという話になりました。

ただ、SDEFの直接解析については1つの「ちょっと困った仕様」がありました。外部ファイルをincludeできる(Xinclude)ようになっており、そのファイルを元のSDEF上に展開するのは、まじめにXML上の情報を分析する必要があります。ファイル・システム上のどこの場所からどのファイルを読み込むのか、という話と……XMLのオブジェクトモデル上のどこに展開するのかという話の両方を処理する必要があります。まじめに組むと、それなりの時間がかかってしまいそうです。

少ない例から推測してScriptを書くことは不可能ではありませんが、「隠れ仕様」が存在していた場合には対処できません。OS側にその機能があれば、そのままそっくり利用できたほうがよいだろうと思われました。

このXincludeの展開を(他力本願で)行うには、どこのレイヤーのどの機能を用いるべきなのか?

matttのOno.frameworkなどもビルドして試してみたものの、Xincludeの展開はソースコードを全文検索しても見つけられず、もうちょっと物理層に近いレイヤーのlibxml2の機能にアクセスする必要があるようでした。

ほかにも、Unix Shell Commandに、「xsltproc」コマンドが存在しており、Xinclude展開を行ってくれるようでした(XSLTを書けば)。スクリプトエディタに任意のアプリケーションをオープンさせればAppleScript用語辞書を表示してくれるわけで、この表示中のSDEFについてはXincludeがすべて解決された状態になっているため、AppleScriptからスクリプトエディタを操作するという手段もないわけではないのですが、もっとスマートに(こっそり)処理したかったので、これは(機能することがわかっていながらも)使えません。

結局、NSXMLDocumentのNSXMLNodeOptionsでNSXMLDocumentXIncludeを指定すると、XMLテキストをオブジェクトに解釈する際に外部ファイルを展開してくれることが判明。

Mail.appのSDEFでいえば、Standard Suiteにinclude指定があり、

元ファイルを読み込んだだけでは完全体のSDEFを取得できません。これを、本AppleScriptを用いて読み込んで解釈すると、

のように、指定パスに存在している「CocoaStandard.sdef」を展開します。ほかにも、Microsoft系のアプリケーションでXincludeを使用しており、本AppleScriptのような処理を経た上でSDEFの分析を行う必要があることでしょう。

これが、今日明日の段階で何か「すごいこと」ができるような存在になることは決してありませんが、この部品が存在していることで異次元の処理ができるようになるような手応えはあります。

AppleScript名:xincludeを有効にしてXML(sdef)読み込み v2.scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2022/07/26
—
–  Copyright © 2022 Piyomaru Software, All Rights Reserved
—

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

set targAppBundleID to "com.apple.mail" –SDEFを取り出すターゲットのアプリケーションのBundle ID

set thePath to POSIX path of (path to application id targAppBundleID)

set aSDEFname to retAppSdefNameFromBundleIPath(thePath, "OSAScriptingDefinition") of me
if aSDEFname = false then return

if aSDEFname does not end with ".sdef" then set aSDEFname to aSDEFname & ".sdef"
set sdefFullPath to thePath & "Contents/Resources/" & aSDEFname
set sdefAlias to (POSIX file sdefFullPath) as alias –sdefのフルパスを求める

–SDEF読み込み(Xincludeの展開が必要な状態)
tell current application
  set theXML to read sdefAlias as «class utf8»
end tell

–NSXMLDocumentの生成、Xincludeを有効に
set {theXMLDoc, theError} to current application’s NSXMLDocument’s alloc()’s initWithXMLString:theXML options:(current application’s NSXMLDocumentXInclude) |error|:(reference)

–XMLを文字データ化
set aDocStr to (theXMLDoc’s XMLData)
set aDocStr2 to (current application’s NSString’s alloc()’s initWithData:(aDocStr) encoding:(current application’s NSUTF8StringEncoding)) as string

–指定パスからアプリケーションのScriptabilityをbooleanで返す
on retAppSdefNameFromBundleIPath(appPath as string, aKey as string)
  set aDict to (current application’s NSBundle’s bundleWithPath:appPath)’s infoDictionary()
  
set aRes to aDict’s valueForKey:(aKey)
  
if aRes = missing value then return false
  
set asRes to aRes as string
  
  
return asRes as string
end retAppSdefNameFromBundleIPath

★Click Here to Open This Script 

Posted in file File path sdef XML | Tagged 12.0savvy | Leave a comment

Keynote, Pages, Numbersが v11.10にアップデート

Posted on 6月 3, 2021 by Takaaki Naganoya

Keynote, Pages, Numbersがv11.10にアップデートしました。Keynoteのみ、AppleScript用語辞書に変更点があります。

Keynoteの変更点はマスタースライドのオブジェクト。従来は「master slide」というオブジェクトだったのが、「slide layout」に変更になっています。理由……についてはよくわかりません。いまさらこんな箇所をいじくる意味がわかりません。

Keynoteの画面を調べてみたら、画面上のマスタースライドの呼称が「スライドレイアウト」に変更になったため、これを反映させたようです。

別にGUI画面上の呼称をオブジェクト名に反映させて変更しなくてもいいんじゃないかと考えますが、やはり意味がよくわかりません。前バージョンまでのくだらないミス(実際に動かしたら分かるレベルのお寒いミス)を連発していた担当者から、別の担当者に変わったような雰囲気がします(知らんけど)。

そんな細かいところは個人的にはドーでもいいので、selection objectとかselected object(スライド上の選択中のオブジェクト)を取得できるようになってほしいです。これができないためにKeynoteで無駄な処理を書かされることが非常に多いので。

こっそり変更したかったのか、一応、macOS 11.5上で「master slide」と入力して構文確認すると、同義語(synonym)として処理され、「slide layout」に自動で書き換えられます。


▲構文確認前


▲構文確認後。「master slide」と入力した箇所が「slide layout」に自動で書き換えられる


▲Keynote v11.01時のAppleScript用語辞書に掲載されていたサンプルAppleScript


▲Keynote v11.10時のAppleScript用語辞書に掲載されていたサンプルAppleScript。こういう部分でミスしてこないあたり、本当に担当者が変わったようにしか見えない

Posted in sdef | Tagged 10.15savvy 11.0savvy Keynote | Leave a comment

未知の予約語

Posted on 5月 3, 2021 by Takaaki Naganoya

AppleScript implementors MLの過去ログを漁っていたら、2006年に作られた資料へのリンクを見つけました。

–> AppleScript Terminology and Apple Event Codes

誰が作った資料かはわかりませんが、AppleEventの4文字コードのコンフリクトが起こらないように、AppleEventコードを調べること、すでにこのような予約語があるのでScriptableなアプリケーションで同様に使えということが目的だったようです。

読んでみると、すでに廃止になったAppleScript Studioの予約語はともかくとして、AppleScript Languageレベルの予約語でも、けっこう知らない予約語があります。

一時期騒ぎになった「linked list」とか「vector」といった予約語は記憶に新しいところですが、構文確認をパスする用語の多いこと多いこと。

無意味語として分類すべきなのか悩ましいものがけっこうあって、驚かされます。C StringsとかPascal Stringsといった予約語もそうですが、見たことのないものばかりです。一部、度量衡の予約語が紛れ込んでいますが、それをのぞいてもけっこう知らないものばかりです。

知っていたからといって自慢できるという種類のものでもなさそうですが、先を見越しすぎたものの実現しなかった「RGB16 color」とか「RGB96 color」あたりが黒歴史案件でしょう。「extended real」あたりで桁数の制限の多い数値型を拡張してもらえたらよさそうなんですが……。

AppleScript系で黒歴史的な予約語といえば、CPU Typeの「Intel 80486」でしょうか。つまり、その頃はMotorola系のCPUを使っていたはずの時期ですが、その時期にi80486で動いていたハードウェアの上でClassic MacOSが動き、その上でAppleScriptの処理系が動いていたことを示唆するもの(?)なわけで……Intel CPU上にCLassic MacOSを移植する「Startrek」プロジェクトの残骸だと(勝手に)考えるとなかなか楽しいものがあります。

AppleScript名:未知の予約語.scpt
text flow
text flows

writing code info
writing code infos
color table

color
condensed
RGB color
RGB colors
C string
C strings

reals
data size

type element info

encoded string
encoded strings
constant
constants
PostScript picture
type event info
event
events

extended real
feet
fixed
font
fixed point
fixed rectangle

file specification
file specifications
full
gallons
type class info
event info
suite info
handler
handlers
hyphens
location reference
floating
zoomable
international text
caps lock down

reference form
reference forms

key kind
modifiers

dates

left

long fixed rectangle
long fixed
linked lists

integers

list or record
long point
long rectangle

machines
unsigned integer

machine location
number or date
negate
no
references

off styles
on styles

outline
ounces

plain

language code

type parameter info

prepositions
print length

script code
writing code

Pascal string
Pascal strings
bounding rectangle

class info
quarts

records
subscript

scripts
shadow

small integer
small real
superscript
strikethrough

styled text
type suite info

styled Unicode text
dash style

pixel map record
RGB16 color
RGB96 color

text style info
text style infos

underline
uniform styles
vector
vectors

application dictionary

system dictionary
booleans

★Click Here to Open This Script 

Posted in sdef | Tagged 10.14savvy 10.15savvy 11.0savvy | Leave a comment

えせScriptable App

Posted on 11月 6, 2020 by Takaaki Naganoya

Macのアプリケーションの中には、Info.plistに「NSAppleScriptEnabled = true」の表記があっても、実際にsdefファイルが入っていなかったり、sdefが入っていても、まったくアプリケーションの機能と関係ないダミー辞書が入っているものがたまにあります。

これを、個人的に「えせScriptable」と呼んでいます。英語に翻訳しづらいですが、Fake Scriptable AppとかDummy Scriptable Appなどと呼ぶところでしょうか。

最悪の「えせScriptable」なアプリケーションはAppleのiBooks Authorでしょうか。電子書籍市場を立ち上げるためには、既存のInDesignなどの他のアプリケーションのデータをiBooks形式にScriptで変換できる必要があると思っていたところに「カス」なAppleScript用語辞書しか入っておらず、「プログラムで変換できないのかー」という落胆をもたらしました。

辞書内容がアプリケーションの機能とぜんぜん合っていない「えせScritable」。実際に、これらの用語を使っても、起動や終了ぐらいはできるものの、アプリケーション本来の機能は1つも呼び出せません。

GUI Scripting経由で無理やりメニュー操作やボタンのクリックは行えますが、これをもって「AppleScriptに対応している」とは言ってはいけないレベルです。

Chipmunk Basicの現行バージョンがScriptableで、本来はAppleScript用語辞書がバンドル中に入っているはずなのですが、確認してみたら入っていないことに気づきました。早速、作者のRon Nicholsonにレポート。さて、どうなりますやら。

現行のUni Detectorでは、これらの「えせScriptable」なアプリケーションも一律「Scriptable」として表示してしまうため、これらをScriptableではないものとして表示を抑止するために専用のデータをバンドル内に格納してチェックするかというところでしょうか。

Microsoft officeの補助アプリケーション類がScriptableな表示になっていますが、単独で起動ができないためにScriptableなアプリケーションの範疇に入れてはいけないところでしょう。ちょっと古めのアプリケーションで、AppleScript Studioで作られているものが存在しており、AppleScript用語辞書が入っているものも見られます。これも、外部からコントロールするための辞書ではないので、正確な意味では「Scriptable」ではありませんが、意外と多いのと古いものが中心なので放置しておいています。

com.nicholson.chipmunkbasic3co		1.368.21
com.kapeli.dashdoc	4.6.7
com.apple.Maps	*
com.apple.iBooksAuthor	*
com.peterborgapapps.Lingon3	*
com.peterborgapapps.LingonX7	*
com.adobe.devicecentral.application	*
com.readpixel.wakeonlan	*
com.bombich.ccc	*
com.microsoft.OrgChart	*
com.microsoft.myday	*
com.microsoft.office_pg	*
com.microsoft.Graph	*
com.microsoft.entourage.database_utility	*
com.microsoft.entourage.database_daemon	*
com.microsoft.outlook.databaseutility	*
com.microsoft.entourage.databasedaemon	*
com.microsoft.entourage.ClipGallery	*
com.microsoft.openxml.chart.app	*
com.microsoft.openxml.excel.app	*
com.microsoft.office.uploadcenter	*
com.microsoft.office.uploadcenter	*
com.tinyspeck.slackmacgap	*
org.mozilla.firefox	*
com.twitter.teitter-mac	*
com.nchsoftware.wavepod	*
com.nchsoftware.expressjp	*
com.digitalspokes.AppKiDo	*
com.parallels.mobile	*
com.epson.East-Photo-Scan	*
Posted in Bug sdef | Tagged 10.13savvy 10.14savvy 10.15savvy 11.0savvy | Leave a comment

iWork Appsのv10.2アップデートが公開される

Posted on 9月 23, 2020 by Takaaki Naganoya

AppleがKeynote/Pages/Numbersのv10.2アッップデートを公開しました。このv10.2から対象OSがmacOS 10.15以降になり、macOS 10.14では最新のKeynote v10.2を使えなくなったことになります。

Keynote v10.2のAppleScript系の機能の差分チェックを(sdefファイルベースで)行ってみたところ、iWorkアプリケーション中でKeynoteのみ機能追加されたことがわかりました。

Keynoteにムービー書き出し機能のAppleScriptオプション機能が追加される

exportコマンドのexport optionsで「movie codecs」と「movie framerates」の指定ができるように機能追加されています。

movie codecs enum
h.264 : H.264
AppleProRes422 : Apple ProRes 422
AppleProRes4444 : Apple ProRes 4444
AppleProRes422LT : Apple ProRes 422LT
AppleProRes422HQ : Apple ProRes 422HQ
AppleProRes422Proxy : Apple ProRes 422Proxy
HEVC : HEVC

movie framerates enum
FPS12 : 12 FPS
FPS2398 : 23.98 FPS
FPS24 : 24 FPS
FPS25 : 25 FPS
FPS2997 : 29.97 FPS
FPS30 : 30 FPS
FPS50 : 50 FPS
FPS5994 : 59.94 FPS
FPS60 : 60 FPS

風の噂によるとどうもARM Macはムービー書き出しが高速なようなので、そのあたりをアピールするためにもムービー書き出し系の機能の拡充は必要ということなのでしょう。

KeynoteのAppleScript用語辞書に構文確認をパスできないバグ持ち予約語が存在

同時に、「こんなんAppleScriptの処理系でコンパイル(構文確認)通るわけないやん、メーカーが何やってますのん?」という予約語がsdef内に書かれていることが一目でわかりました。

「h.264?」

この「h.264」の予約語はexportコマンドのexport optionsのmovie codecsのEnum内に書かれています。

        <enumeration name="movie codecs" code="Knmc">
            <enumerator name="h.264" code="Kmc1" description="H.264">
                <cocoa string-value="AVVideoCodecTypeH264" />
            </enumerator>

macOS 10.15.6上で確認したところ、見事に構文確認時にエラーになります。

Apple製のアプリケーションのAppleによるスクリプティング定義内容がまともに動きません。こうした事態は理解に苦しむものがあります。100%動作確認していないとしか思えません。

ここは、記号入りの予約語では言語処理系的に構文確認すらパスできないので、「h.264」ではなく記号を含まない「h264」ないし「H264」という予約語にすべきです。AppleScript系の機能を追加していただくのは前向きでよいと思いますが、メーカーとして一度も動作確認しないで機能をリリースするというのはいかがなものでしょう?

そんなところに凝っていないで、選択中のオブジェクトを取れる属性「selected objects」とか、テキストオブジェクトの縦書き制御属性「vertical」などをつけたほうが実用性があって助かります。機能追加自体はたいした作業ではありませんが、ぜひ動作確認した上でリリースしていただきたいところです。

AppleScript名:keynote movie export test
–Works with Keynote v10.2 or later
set aTagFile to ((path to desktop) as string) & "testOut.m4v"

tell application "Keynote"
  set exOpt to {compression factor:1.0, movie format:native size, class:export options}
  
–set exOpt to {compression factor:1.0, movie format:native size, movie codec:h.264, class:export options}–this cause error
  
export document 1 to file aTagFile as QuickTime movie with properties exOpt
  
end tell

★Click Here to Open This Script 

日頃からMac App Storeのレビューアーの血も涙もない(でも、ツッコミどころ満載の)リジェクトに遭っている身からすれば、こんなのリジェクト案件です。

個人的には信頼度の問題からmacOS 10.15は「パス」なので、macOS 11.0 Big SurがRelease時にコケないことを祈るのみです(メールが消えるとかいう話が一番OSの信頼度を下げる)。macOS 10.13, “Vista”という史上最悪・最低の大失敗をやらかして以来、「Release版のOSがBetaよりも低品質」という昨今のmacOS。10.13もBetaの時にはよかったのに、Release版で大崩壊を起こして見るも無残な姿に成り果てました。10.14もBetaの段階でGUI Scriptingの認証系でひどいバグがあって、「とても使えない」と判断。10.14.6まで待ってようやく手を出す気になったほど。

macOS 11.0, Big SurはBeta段階でも珍しく好印象で(GUIまわりの仕様はコロコロ変わるけど)、macOS 10.15みたいにBeta段階で「もう、これはダメ!」という話も聞きません(Relase時に紹介記事を書かなかったOSは10.15がはじめてです。10.15の崩壊度はひどかった)。macOS 11.0, Big Surには、macOS 10.13のような「Release版の大崩壊」を起こしてほしくないものです。

Posted in Bug sdef | Tagged 10.15savvy 11.0savvy Keynote Numbers Pages | Leave a comment

AS Dictionaryのメンテナンス?

Posted on 9月 20, 2020 by Takaaki Naganoya

指定アプリケーションのAppleScript用語辞書(sdef)をHTMLに書き出すツール「AS Dictionary」は有用なツールです。もともと、hasがScriptingのための独自機構「objc-appscript」を作ったときの補助ツールでしたが、そのobjc-appscriptそのものは見るべきものがありませんでした(OS X 10.7あたりのOS側の構造改変で動かなくなってプロジェクト終了)。

補助ツールのAS Dictionaryは本来の目的とは完全に別の「sdefの差分検出」のためのツールとして利用されてきました。

ただ、最近のmacOS上のアプリケーションに対応し切れない状態になってきています。sdefに外部ファイルをincludeする形で、一部の定義部分を外部に追い出しているアプリケーションも出てきているため、これに対応できていないAS Dictionaryは、完全なsdefのHTML書き出しができる状態ではなくなっています。つまり、includeされている部分は書き出されないという問題を抱えています。

さらに、処理コアがPythonで書かれており、中にPythonの処理系そのものを入れた構造の(無理のある)アプリケーションであり、macOS 11.0, Big Surでついに機能しなくなってしまいました。

本ツールはMugginsoftでホスティングして改変が加えられたりしていましたが、Mugginsoft自体のWebサイトがなくなって配布も行われなくなったという状況です。Jonathan Mitchell氏のその後の消息については、かんたんにLinked Inで見つかりました。元気にしているようです。

Tweets by mugginsoft

アプリケーションパッケージの中をのぞいてみると、Pythonのコードがまるまるソースコードのまま格納されており、400行程度のコード(ASDictionary.py)であることを確認でき、内容も読めます。

まずは、sdefのバージョン間の差分検出にHTMLに書き出したsdefを用いるべきなのか、それともsdefそのもので差分検出すべきなのかという話になるでしょう。

Level 0:差分検出のためsdefをHTMLに書き出すという方法そのものを破棄。sdef同士の差分検出を行う。AS Dictionaryはここで終了
Level 1:Pythonコードをそのまま使って、現代の環境に適合する最低限度の改修を行う
Level 2:Pythonのコードを全部AppleScriptObjCに書き直す

Level 0かLevel 2の両極端な対応しかなさそうなのですが、どうもLevel 0になりそうな雰囲気です。

Posted in sdef | Tagged 11.0savvy AS Dictionary | Leave a comment

HandBrakeがAppleScriptに対応したのはいいんだけど……

Posted on 7月 23, 2020 by Takaaki Naganoya

リッピングやメディアトランスコーディングを行うソフトウェア「HandBrake」がAppleScriptに対応するという話を少し前に聞いていました。今日確認したらアップデートしてAppleScript用語辞書がついていることを確認。

ただし……

AppleScript用語辞書がまるっきりダメです。使いものにならない用語ばかりで、何かよそのアプリケーションの用語辞書をコピーしただけのようです。

この辞書では、アプリケーションを起動してバージョンなどの情報を確認するのと、指定のファイルをオープンするぐらいしかできません。キューに指定ムービーを追加するとか、エンコーディング形式を指定するとか、最重要コマンドである「start」といった用語も何もありません。

正直、この出来だと「HandBrake CLI」経由でHandBrakeのコア機能を呼び出した方が使いでがあると思います。

AppleScript名:HandBrakeの情報を取得.scpt
tell application "HandBrake"
  properties
  
–> {frontmost:false, class:application, name:"HandBrake", version:"1.3.3"}
end tell

★Click Here to Open This Script 

AppleScript名:handBrakeで指定ファイルをオープン.scpt
set aFile to choose file

tell application "HandBrake"
  open aFile
end tell

★Click Here to Open This Script 

Posted in sdef | Tagged 10.13savvy 10.14savvy 10.15savvy 11.0savvy HandBrake | Leave a comment

Wikipedia経由で2つの単語の共通要素を計算するcommon elements Lib Script Library

Posted on 2月 28, 2020 by Takaaki Naganoya

現在作成中のアプリケーションの副産物として生まれた「common elements Lib」AppleScript Libraryです。2つの単語の共通要素を計算して返します。

# v1.1にアップデートしました(ダウンロード先URLはかわらず)。ページ下部のテンプレート部分の余計なリンクを拾わないように改善したため、テンプレート部分のリンクが多い項目に対して大きな効果を発揮します

–> Download archive

アーカイブをダウンロードして展開し、~/Library/Script Librariesフォルダに「common elements Lib.scptd」を入れるとAppleScriptから呼び出せるようになります。

macOS 10.10以降で動作するはずですが、開発は10.14上で、動作確認は10.13/10.14/10/15上でのみ行なっています。

この、2つのキーワードの共通要素を求める処理は「マッキー演算」と呼んでおり、男性アイドルグループ「SMAP」と、男性シンガーソングライター「槇原敬之」(マッキー)氏の共通要素を演算で求めることを目的として企画されました。「SMAP」はWikipedia上でも最大級の要素数を持つ項目であり、1,400項目以上のリンク要素を擁しています。

Wikipedia REST APIの仕様ではリンク要素を500項目までしか一度に取得できません。SMAPを処理するためには、複数ページにまたがるリンク取得の処理をこなすことが必要であり、「マッキー演算」は言葉のバカっぽさとは裏腹に、それなりの技術力が要求される、そこそこむずかしい処理なのです。

本ライブラリを用いて、WikipeidaにREST API経由で検索司令を出すわけですが、英語のスペルの単語を受け付けるWikipediaもあれば、日本語やアラビア語Wikipediaなどのようにその言語向けの書き換えを行ったデータで検索するものもあり、割とまちまちであることがわかりました。そのあたりは、sdefに書いておいたサンプルScriptを見ていただくのがよいでしょう。

本ライブラリでは、演算対象とする単語はWikipediaに掲載されているものに限られています。実際に、日本語環境で「スティーブ・ジョブズ」と「ラリー・テスラー」の共通項目を計算すると、

--> {"パロアルト研究所", "Smalltalk", "アメリカ合衆国", "Lisa (コンピュータ)", "アップル・ニュートン", "Macintosh", "アップル (企業)", "Macworld", "スタンフォード大学"}

「スティーブ・ジョブズ」と「ロス・ペロー」の共通項目を計算すると、

--> {"NeXT", "アル・ゴア", "統合典拠ファイル", "実業家", "IBM", "ゼネラルモーターズ", "SNAC", "アメリカ合衆国", "国際標準名称識別子", "孫正義", "ソフトバンク", "国立国会図書館", "フランス国立図書館", "アメリカ議会図書館管理番号", "CiNii", "バーチャル国際典拠ファイル"}

のような結果を返してきます。

冒頭で述べた「SMAP」と「槇原敬之」の共通項目を計算すると、

--> {"スポーツニッポン", "ABO式血液型", "テレビ朝日", "東京都", "社長", "エフエム東京", "ミュージックステーション", "J-POP", "第42回NHK紅白歌合戦", "大阪城ホール", "日本", "We are SMAP!", "ミリオンセラー", "小倉博和", "インターネットアーカイブ", "日本武道館", "ニッポン放送", "リクルートホールディングス", "日刊スポーツ", "第58回NHK紅白歌合戦", "フジテレビジョン", "世界に一つだけの花"}

のようになります。

おおよその主要言語に対応していますが、ロシア語をはじめとするキリル文字の言語を指定すると、なぜか結果が返ってきません。これが、キリル文字のエンコーディングに関する(こちら側の実装がまずい)問題なのか、サーバー側がREST APIをサポートしていないのか(Wikipediaサーバー側の問題)はわかりません。
→ ロシア語のクエリーも処理できることを確認しました

ここでは、だいたいの「いい感じのキーワード」を例として出していますが「George Lucas」と「Steven Spielberg」などの近い単語を指定すると結果が400個以上返ってきます。
→ v1.1における改良により、400個以上のリンクを66個まで減少させました(不要なフッター部分のリンクを拾わないようにした)

膨大な項目から必要な要素を選択するInterfaceをみつくろってテストをしてはいるのですが、iOS上でよさそうに見えてもMac上で動かすといまひとつだったり、なかなか合うものが見つかりません(超多項目選択UI)。

–> Watch Demo

こうした計算結果をもっと減らす方法や、これらの多項目の計算結果からGUI上で項目選択する方法などが自分たちでは見つからなかったので、ライブラリとして公開して広く意見やアイデアを募ろうと考えました。多言語のWikipediaへの問い合わせを行ったり、問題点を洗い出すことも目的の1つです。前述のとおり、ロシア語系のWikipediaに対するアクセスに問題がある点については調査が必要です。

余談ですが、Steve JobsとLarry Teslerの関連項目演算を行おうとしても、Larry Teslerの項目がなかったり、Xerox PARCへのリンクがないために演算結果にこれが含まれない言語のWikipediaがいくつか見られました。コンピュータ史上重要な偉人への敬意をこめ、ぜひ追記していただきたいと考えるものです(という話を日本語で書いても意味がない?)。

AppleScript name:sample.scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2020/02/28
—
–  Copyright © 2020 Piyomaru Software, All Rights Reserved
— http://www.piyocast.com

use comLib : script "common elements Lib"

–English
set aWord to "Steve Jobs"
set bWord to "Larry Tesler"
set commonResEN to list up common elements with {aWord, bWord} with language "en"
–> {"The New York Times", "Computer History Museum", "Alan Kay", "International Standard Book Number", "California", "Steve Jobs", "Computer mouse", "John Markoff", "Ethernet", "Stanford University", "Counterculture of the 1960s", "Fortune (magazine)", "Tablet computer", "Apple Lisa", "Apple Inc.", "Associated Press", "Graphical user interface", "International Standard Serial Number", "Apple Computer", "Macintosh 128K", "Xerox Alto"}

–日本語(Japanese)
set aWord to "スティーブ・ジョブズ" –Steve Jobs
set bWord to "ラリー・テスラー" –Larry Tesler
set commonResJP to list up common elements with {aWord, bWord} with language "jp"
–> {"パロアルト研究所", "Smalltalk", "アメリカ合衆国", "Lisa (コンピュータ)", "アップル・ニュートン", "Macintosh", "アップル (企業)", "Macworld", "スタンフォード大学"}

–中文(Simplified Chinese)
set aWord to "史蒂夫·乔布斯" –Steve Jobs
set bWord to "拉里·泰斯勒" –Larry Tesler
set commonResZH to list up common elements with {aWord, bWord} with language "zh"
–> {"母校", "美國", "帕羅奧多研究中心"}

—한국어(Korean)
set aWord to "스티브 잡스" –Steve Jobs
set bWord to "빌 게이츠" –Bill Gates
set commonResKO to list up common elements with {aWord, bWord} with language "ko"
—> {"가상 국제 전거 파일", "위키인용집", "게마인자메 노름다타이", "네덜란드 왕립도서관", "국제 표준 도서 번호", "IBM", "SNAC", "CiNii", "개인용 컴퓨터", "BIBSYS", "영어", "국제 표준 명칭 식별자", "오스트레일리아 국립도서관", "LIBRIS", "체코 국립도서관", "미국", "스페인 국립도서관", "뮤직브레인즈", "프랑스 국립도서관", "이스라엘 국립도서관", "일본 국립국회도서관", "미국 의회도서관 제어 번호", "전거 통제", "국립중앙도서관", "WorldCat Identities", "실리콘 밸리의 신화", "프랑스 대학도서관 종합목록", "위키미디어 공용"}

–svenska
set aWord to "Steve Jobs"
set bWord to "Ross Perot"
set commonResSV to list up common elements with {aWord, bWord} with language "sv"
–> {"USA", "IBM", "Forbes", "Entreprenör", "Libris (bibliotekskatalog)"}

–Deutsch
set aWord to "Steve Jobs"
set bWord to "Larry Tesler"
set commonResDE to list up common elements with {aWord, bWord} with language "de"
–> {"Objektorientierte Programmierung", "Apple", "Apple Macintosh", "Xerox PARC", "Virtual International Authority File", "The New York Times", "Kalifornien", "Apple Lisa"}

–français
set aWord to "Steve Jobs"
set bWord to "Larry Tesler"
set commonResFR to list up common elements with {aWord, bWord} with language "fr"
–> {"The New York Times", "Palo Alto Research Center", "Informaticien", "Californie", "Apple", "États-Unis", "Autorité (sciences de l’information)"}

–Nederlands
set aWord to "Steve Jobs"
set bWord to "Larry Tesler"
set commonResNL to list up common elements with {aWord, bWord} with language "nl"
–> {"Verenigde Staten (hoofdbetekenis)", "Palo Alto Research Center", "Apple Macintosh", "Xerox", "Apple Inc.", "Apple Lisa", "Apple Newton"}

–italiano
set aWord to "Steve Jobs"
set bWord to "Larry Tesler"
set commonResIT to list up common elements with {aWord, bWord} with language "it"
–>{"Apple", "Stati Uniti d’America", "Xerox Palo Alto Research Center", "Informatico"}

–español
set aWord to "Steve Jobs"
set bWord to "Ross Perot"
set commonResES to list up common elements with {aWord, bWord} with language "es"
–> {"Emprendedor", "Library of Congress Control Number", "Wikidata", "IBM", "Enciclopedia Británica", "Wikimedia Commons", "Empresario", "CiNii", "National Diet Library", "Estados Unidos", "National Library of the Czech Republic", "Virtual International Authority File", "Bibliothèque nationale de France", "International Standard Name Identifier", "Integrated Authority File", "Système universitaire de documentation", "ISBN"}

–polski
set aWord to "Steve Jobs"
set bWord to "Larry Tesler"
set commonResPL to list up common elements with {aWord, bWord} with language "pl"
–> {"Apple Inc.", "Virtual International Authority File", "Xerox PARC"}

–Tiếng Việt
set aWord to "Steve Jobs"
set bWord to "Larry Tesler"
set commonResVI to list up common elements with {aWord, bWord} with language "vi"
–> {"Hoa Kỳ", "Apple Lisa", "California", "Apple Inc."}

–Arabic
set aWord to "ستيف جوبز"
set bWord to "روس بيرو"
set commonResAR to list up common elements with {aWord, bWord} with language "ar"
–> {"مكتبة البرلمان الوطني", "رقم الضبط في مكتبة الكونغرس", "رائد أعمال", "المكتبة الوطنية لجمهورية التشيك", "ملف استنادي متكامل", "ملف استنادي دولي افتراضي", "المكتبة الوطنية الفرنسية", "سايني", "ديل", "آي بي إم", "لغة إنجليزية", "ضبط استنادي", "حزب سياسي", "مهنة", "مدرسة أم", "واي باك مشين", "الولايات المتحدة", "المحدد المعياري الدولي للأسماء", "دولار أمريكي"}

–português
set aWord to "Steve Jobs"
set bWord to "Larry Tesler"
set commonResPT to list up common elements with {aWord, bWord} with language "pt"
–> {"Macintosh", "Alan Kay", "Apple Newton", "Povo dos Estados Unidos", "Língua inglesa", "Estados Unidos", "Ciência da computação", "Apple", "Califórnia", "Base Virtual Internacional de Autoridade"}

–Català
set aWord to "Steve Jobs"
set bWord to "Larry Tesler"
set commonResCA to list up common elements with {aWord, bWord} with language "ca"
–> {"Control d’autoritats", "Virtual International Authority File", "Apple Macintosh", "Apple Inc", "Interfície gràfica d’usuari"}

–Bahasa Indonesia
set aWord to "Steve Jobs"
set bWord to "Larry Tesler"
set commonResNO to list up common elements with {aWord, bWord} with language "id"
–> {"California", "Biografi", "Amerika Serikat"}

–magyar
set aWord to "Steve Jobs"
set bWord to "Larry Tesler"
set commonResHU to list up common elements with {aWord, bWord} with language "hu"
–> {"Amerikai Egyesült Államok", "Informatikus", "Wikimédia Commons", "Stanford Egyetem", "Nemzetközi Virtuális Katalógustár"}

–euskara
set aWord to "Steve Jobs"
set bWord to "Larry Tesler"
set commonResEU to list up common elements with {aWord, bWord} with language "eu"
–> {"Xerox", "Informatikari", "Ingeles", "Apple Inc.", "Ameriketako Estatu Batuak", "Wikidata", "Smalltalk", "Virtual International Authority File", "Stanford Unibertsitatea", "Wikimedia Commons"}

–Türkçe
set aWord to "Steve Jobs"
set bWord to "Larry Tesler"
set commonResTR to list up common elements with {aWord, bWord} with language "tr"
–> {"The New York Times", "Apple", "Amerika Birleşik Devletleri", "Kaliforniya"}

★Click Here to Open This Script 

AppleScript name:sample2
—
–  Created by: Takaaki Naganoya
–  Created on: 2020/02/28
—
–  Copyright © 2020 Piyomaru Software, All Rights Reserved
— http://www.piyocast.com

use comLib : script "common elements Lib"

set sList to supported lang codes
–> {"en", "ceb", "sv", "de", "fr", "nl", "ru", "it", "es", "pl", "war", "vi", "jp", "zh", "ar", "pt", "uk", "fa", "ca", "sr", "no", "id", "ko", "fi", "hu", "sh", "cs", "ro", "eu", "tr", "ms", "eo", "hy", "bg", "he", "da", "ce", "zh-min-nan", "sk", "kk", "min", "hr", "et", "lt", "be", "el", "azb", "sl", "gl", "az", "simple", "ur", "nn", "hi", "th", "ka", "uz", "la", "ta", "vo", "arz", "cy", "mk", "tg", "lv", "ast", "mg", "tt", "af", "oc", "bs", "bn", "ky", "sq", "zh-yue", "tl", "new", "te", "be-tarask", "br", "ml", "pms", "nds", "su", "ht", "lb", "jv", "sco", "mr", "sw", "pnb", "ga", "szl", "ba", "is", "my", "fy", "cv", "lmo", "an", "ne", "pa", "yo", "bar", "io", "gu", "wuu", "als", "ku", "scn", "kn", "ckb", "bpy", "ia", "qu", "mn", "bat-smg", "vec", "wa", "si", "or", "cdo", "gd", "yi", "am", "nap", "ilo", "bug", "xmf", "mai", "hsb", "map-bms", "fo", "diq", "mzn", "sd", "li", "eml", "sah", "nv", "os", "sa", "ps", "ace", "mrj", "frr", "zh-classical", "mhr"}

–"ru", "uk", "sh", "bg" seems not to work… "ms" or later codes seems not to work (depends on Wikipedia Server spec)….

★Click Here to Open This Script 

Posted in Internet Language Natural Language Processing REST API Script Libraries sdef | Tagged 10.10savvy 10.11savvy 10.12savvy 10.13savvy 10.14savvy 10.15savvy | 1 Comment

display drop dialog Script Library

Posted on 1月 16, 2020 by Takaaki Naganoya

指定UTIのファイルのFinderからのドラッグ&ドロップを受け付けるAppleScript Libraries「display drop dialog」をリリース、フリー配布いたします。

# 本ライブラリはEdama2さんのScriptに若干の改変を行い、sdefをつけてパラメータのエラー処理を行い、コードサインしてライブラリ化したものです

–> Download display drop dialog Script Library (To ~/Library/Script Libraries/)

本ライブラリは、指定UTIの書類のドラッグ&ドロップを受け付けるダイアログをAppleScriptから手軽に使えるようにするものです。macOS 10.14以降で動作します。

現在のAppleのTim Cook体制は、セキュリティ強化の美名のもとに「動かないコンピュータ」を目指し、各種機能を阻害する方向に進んでいます。

AppleScriptの世界はその中でも自由度が比較的高い状態にありますが、それでもmacOS 10.12以降では、AppleScriptドロップレットにFinderからドラッグ&ドロップしても、Finderの拡張属性(Xattr)がついたファイルは無視されたりと、なかなか困ります。

そこで、Finderからのドラッグ&ドロップ操作を通常の(Applet書き出ししていない)AppleScript、とくにScript Menuから呼び出す形式のAppleScriptで使えるようにすることを目的として本ライブラリを作成しました。

本ライブラリを用いることで、ドロップレットを作らなくても、Script Menuから呼び出した普通のAppleScriptにファイルのドラッグ&ドロップの受信機能を追加できます。セキュリティと機能性(ドラッグ&ドロップ)を両立させるため、すべてのScripterに欠かすことのできないライブラリになるものと期待しています。

本ライブラリのAppleScript用語辞書には実行イメージ(画面キャプチャ)およびサンプルScriptを入れてあり、実行時の様子やサンプルスクリプト(本Blogと同様のワンクリックで内容が転送されるリンクつき)を確認できるようになっています。

AppleScript名:accept AppleScript documents
use dropLib : script "display drop dialog"

set aMainMes to "Drop AppleScript"
set aSubMes to "Drag and Drop AppleScript files here"
set aUTI to "com.apple.applescript.script"
set execButtonTitle to "Execute"
set aRes to (display drop dialog aUTI main message aMainMes sub message aSubMes with initial folder "" OK button title execButtonTitle)
–> {alias "Machintosh HD:Users:me:Documents:display drop dialog:accept PNG images.scpt", alias "Machintosh HD:Users: me:Documentsaccept Markdown documents.scpt"}

★Click Here to Open This Script 

AppleScript名:accept Markdown documents
use dropLib : script "display drop dialog"

set aMainMes to "Drop Markdown Documents"
set aSubMes to "Drag and Drop Markdown documents here"
set aUTI to "net.daringfireball.markdown"
set execButtonTitle to "Execute"
set aRes to (display drop dialog aUTI main message aMainMes sub message aSubMes with initial folder "" OK button title execButtonTitle)
–> {alias "Machintosh HD:Users:me:Documents::–Book 11 「Blog Archives vol5 2013-2014」:2013:01:201301013.md", alias "Machintosh HD:Users:me:Documents::–Book 11 「Blog Archives vol5 2013-2014」:2013:01:201301012.md"}

★Click Here to Open This Script 

AppleScript名:accept PNG images with initial folder contents
use scripting additions
use dropLib : script "display drop dialog"

set aMainMes to "Drop PNG"
set aSubMes to "Drag and Drop png images here"
set aUTI to "public.png"
set execButtonTitle to "Execute"
set iFolder to path to pictures folder –At first, PNG files in this folder is displayed
set aRes to (display drop dialog aUTI main message aMainMes sub message aSubMes with initial folder iFolder OK button title execButtonTitle)
–> {alias "Machintosh HD:Users:me:Pictures:1015sedhelp2.png", alias "Machintosh HD:Users:me:Pictures:574G01.png", alias "Machintosh HD:Users:me:Pictures:macDown1.png", alias "Machintosh HD:Users:me:Pictures: 2017-09-27 19.33.53.png", alias "Machintosh HD:Users:me:Pictures:2018-11-01 10.54.06.png"

★Click Here to Open This Script 

Posted in dialog GUI PRODUCTS Script Libraries sdef | Tagged 10.14savvy 10.15savvy | Leave a comment

最前面のアプリケーションの用語辞書を表示する v4

Posted on 1月 8, 2020 by Takaaki Naganoya

最前面のアプリケーションのAppleScript用語辞書をオープンするAppleScriptです。

macOS標準装備のScript Menuに入れて呼び出すことを前提に作りました。はるかかなた昔に作って、OSバージョンが上がるごとに細かい改修を行なって使い続けているものです。

この手のScriptは日常的にAppleScriptを書いている人間なら、たいてい書いてみたことがあるはずです。しかし、あまり生真面目なアプローチでアプリケーションバンドル中のsdefのパスを求めてオープンといった処理を行っていると、「例外」にブチ当たって困惑します。

sdefファイルを直接持っていないAdobe Creative Cloud製品です。InDesignあたりがそうなんですが、直接sdefを保持しておらず、どうやら実行時に動的に組み立てるようで、絶体パス(absolute path)で指定してもsdefをオープンできません。

また、Microsoft Office系アプリケーションのsdefも、外部の(OS側のsdef)テンプレートをincludeするようなので、生真面目に対象アプリケーションのInfo.plistの情報をもとにアプリケーションバンドル中のsdefファイルをオープンするように処理すると、sdefの一部のみを表示するようになってしまって、sdef全体を表示することができません。

そうしたもろもろの問題に当たって、結局アプリケーションそのものをScript Editorでオープンするように指定しています。

AppleScript名:–このアプリケーションの用語辞書を表示する v4
— Created 2017-07-23 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

–最前面のプロセスのファイルパスを取得する
set aFile to path to frontmost application
set aRec to (getAppPropertyFromInfoPlist(aFile, "NSAppleScriptEnabled") of me) as boolean

–スクリプト用語辞書をScript Editorでオープンする手順
if aRec = true then
  –OS X 10.10でScript Editor側からアプリケーションをオープンしてもダメだったので、Finder側からScript Editorで指定アプリをオープンすることに
  
try
    tell application "Finder"
      set apFile to (application file id "com.apple.scripteditor2") as alias
      
open aFile using application file apFile
    end tell
  on error
    tell application id "com.apple.scripteditor2"
      open aFile
    end tell
  end try
  
  
tell application id "com.apple.scripteditor2" to activate
  
else
  display dialog "本アプリケーションは、各種OSA言語によるコントロールに対応していません。" buttons {"OK"} default button 1 with icon 2 with title "Scripting非対応"
end if

on getAppPropertyFromInfoPlist(aP, aPropertyLabel)
  set aURL to current application’s |NSURL|’s fileURLWithPath:(POSIX path of aP)
  
set aBundle to current application’s NSBundle’s bundleWithURL:aURL
  
set aDict to aBundle’s infoDictionary()
  
  
set aRes to aDict’s valueForKey:aPropertyLabel
  
if aRes is not equal to missing value then
    set aRes to aRes as anything
  end if
  
  
return aRes
end getAppPropertyFromInfoPlist

★Click Here to Open This Script 

Posted in sdef | Tagged 10.12savvy 10.13savvy 10.14savvy 10.15savvy Script Editor | Leave a comment

macOS 10.14でScript Editorのsdefから「execute」コマンドが除去されていた

Posted on 12月 16, 2019 by Takaaki Naganoya

macOS 10.14のスクリプトエディタのAppleScript用語辞書(sdef)から「execute」コマンドが除去されていることに気づきました。

このことは、別に「GUI側からスクリプトエディタ上のAppleScriptを実行できなくなった」ということではありません。

スクリプトエディタ自体もAppleScriptからコントロールできる「スクリプタブルな」アプリケーションであり、macOS 10.14以降ではAppleScriptからスクリプトエディタをコントロールしてAppleScriptを実行させることができなくなった、ということです。

セキュリティ向上のためにexecuteコマンドを削除したように見えますが、そういうことをやったならRelease Notesに明記しておいてほしいものです。

Piyomaru Context menu AssistantのmacOS 10.13版を10.14上で動作確認していたら、動かなくなっているものがあって(クラッシュするものも出てきております)、原因を確認していたら一部の予約語が、

with timeout of 36000 seconds --1時間のタイムアウト
	«event sedsexec»
end timeout

のように文字化け。これによって「execute」(Script実行)の予約語が抹消されたことがわかりました。スクリプトエディタ自体をコントロールしてScriptを実行させるケースは少ないので、世界中でも私ぐらいしか影響はないことでしょう。ちなみに、サードパーティのAppleScript統合開発環境であるScript Debuggerにはexecuteコマンドがあります。

別にスクリプトエディタでAppleScript書類をオープンして実行するような迂遠かつマニアックかつ「もっと簡単な手段があるのにわざわざそんなことしなくても」というアクションを好き好んで行う人はほとんどいないでしょう。全人類のうち、私以外にダメージはないことでしょう。

実際にスクリプトエディタにexecuteコマンドを送って実行していた例というのは、実行時間の計測を行うAppleScriptです。地味にそういうのを使っていました(最近は、Shane StanleyのScript Geekで処理時間を計測するパターンが多いので使っていませんでしたが)。


▲macOS 10.13.6


▲macOS 10.13.6


▲macOS 10.14.6


▲macOS 10.14.6


▲macOS 10.15.2


▲macOS 10.15.2

Posted in sdef | Tagged 10.14savvy 10.15savvy Script Editor | Leave a comment

Post navigation

  • Older posts

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

Google Search

Popular posts

  • 開発機としてM2 Mac miniが来たのでガチレビュー
  • macOS 13.6.5 AS系のバグ、一切直らず
  • CotEditorで2つの書類の行単位での差分検出
  • Apple純正マウス、キーボードのバッテリー残量取得
  • macOS 15, Sequoia
  • 初心者がつまづきやすい「log」コマンド
  • ディスプレイをスリープ状態にして処理続行
  • 指定のWordファイルをPDFに書き出す
  • Adobe AcrobatをAppleScriptから操作してPDF圧縮
  • メキシカンハットの描画
  • 与えられた文字列の1D Listのすべての順列組み合わせパターン文字列を返す v3(ベンチマーク用)
  • Pages本執筆中に、2つの書類モード切り替えに気がついた
  • 2023年に書いた価値あるAppleScript
  • Pixelmator Pro v3.6.4でAppleScriptからの操作時の挙動に違和感が
  • AdobeがInDesign v19.4からPOSIX pathを採用
  • Safariで「プロファイル」機能を使うとAppleScriptの処理に影響
  • Cocoa Scripting Course 続刊計画
  • NaturalLanguage.frameworkでNLEmbeddingの処理が可能な言語をチェック
  • macOS 14.xでScript Menuの実行速度が大幅に下がるバグ
  • Numbersで選択範囲のセルの前後の空白を削除

Tags

10.11savvy (1102) 10.12savvy (1243) 10.13savvy (1392) 10.14savvy (587) 10.15savvy (438) 11.0savvy (283) 12.0savvy (207) 13.0savvy (167) 14.0savvy (117) 15.0savvy (94) CotEditor (64) Finder (51) iTunes (19) Keynote (115) NSAlert (61) NSArray (51) NSBitmapImageRep (20) NSBundle (20) NSButton (34) NSColor (51) NSDictionary (27) NSFileManager (23) NSFont (19) 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 (72) Pages (53) Safari (44) Script Editor (26) WKUserContentController (21) WKUserScript (20) WKWebView (23) WKWebViewConfiguration (22)

カテゴリー

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

アーカイブ

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

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

メタ情報

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

Forum Posts

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

メタ情報

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