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

カテゴリー: OSA

as anything

Posted on 4月 3, 2019 by Takaaki Naganoya

as anythingについてまとまった情報がなかったので、まとめておきました。結論めいたものはとくになく、ただ、手持ちの情報を並べてみただけの内容なのでご容赦ください。「これはこうあるべき!」とかいう提言とかは一切ありません。

割と最近なas anythingとの遭遇

つい最近まで、ながらく存在自体を知らなかったのが、このanythingという予約語です。

AppleScriptの用語辞書をASObjC Explorer 4で書いて試していたとき、パラメータの型に「any」というものが存在していることには気づいていましたが、それでも「anything」という予約語があることには気づきませんでした。

本格的に知ったのは、applescript-stdlibを漁っていたときです。

同ライブラリはトリッキーなScriptの記述方法の見本市みたいになっていて、内容自体の完全理解についてはサジを投げた状態でしたが、見たことのない記述にいろいろ行き当たりました(もっと読みやすく書いてほしかった ^ー^;;)。

delegateの呼び出し先にscriptオブジェクト内部のハンドラを指定したりと、「そんな書き方できるんだ。やらんけど」と、まるで古文書をひもとくような感覚(これを見ていると、こーゆー風にblocks構文をAppleScriptでも記述できればいいのに、と思います)。

そこで見つけた「as anything」表記。これは一体なんなんでしょう?

いい加減に使えてとても便利なas anything

実際に動かしてみたところ、「あーー、この機能昔から欲しかったわー」という内容でした。anonymous classとでもいうのでしょうか。castするときにclass名を指定しないワイルドカードなclassと理解しました。

「as anything」でAppleScriptのデータ型はそのまま、AppleScriptのデータ型にcast可能なCocoaのデータはAppleScriptのデータ型に変換。変換不能なCocoaのデータ型についてはそのまま、という処理をしてくれます。

# ただし要素数が1つのNSArrayをas anythingでAppleScript Objetに変換すると、listではなく中身のデータが取り出されてしまう(型が合わなくなる)ので、注意が必要とのこと(Thanks Shane!)
# なので、あらかじめNSArrayが返ってくることがわかっている場合には、as list。NSArrayか他のデータ(missing valueとか)が返ってくる場合には、as {missing value, list} などとするとよいでしょう

BridgePlus的にいえば、「ASify without BridgePlus」といったところでしょうか。CocoaとAppleScriptの間でデータをやりとりするのにえっらく都合がよかったのです。かくして、「as anything」を愛用しまくるスタイルが確立。

ただ、anythingは言語仕様のはざまで埋もれかけていた「枝葉末節」の中の一番の「枝葉」ともいうべき、言語仕様の極北。AppleScript Language Guideにも記載されていないほどの枝葉仕様。

AppleScriptObjCのプログラム中に書くと、予約語が用意されていないためか「as anything」が「as list of string or string」などと解釈されてしまいます(動作自体はanythingと同じ)。

anythingについては、Apple側がわりとぞんざいに仕様を放置していたきらいがあります。問題が起こらないかぎり放っておこう、と。as «class isot»のようにある日突然(Mac OS X 10.5で)消えてなくなったりしないかちょっと不安に感じたこともありましたが、一応まがりなりにも予約語が割り振られているので(生Apple Eventを記述させられないので)、そんなに簡単に消えないとは思います。

主要開発環境で足並みそろわず

雑に放置していたAppleに対して、この問題に正面から向き合っていた集団が存在します。それが、Script DebuggerのメーカーであるLate Night Softwareです。

macOS 10.12や10.13上ではあいかわらずASOCのプログラムでは「as anything」が「as list of string or string」と解釈されますが、macOS 10.14で対応に差が出ました。

Script Debugger上では「anything」が「any」と解釈され、スクリプトエディタ上では「anything」と解釈されます。

macOS 10.14上でのスクリプトエディタで「as anything」が「as list of string or string」のように化けないのはいいと思います。ただ、Script DebuggerのメーカーであるLate Night Software側ではこれに「any」という別の予約語を割り振ったようで、、、、足並みがそろっていません。

一応、macOS 10.14上のスクリプトエディタv2.11上で「as anything」と記述したScriptを、同じくmacOS 10.14上のScript Debuggerに持っていくと「as any」と表示されます。いったん中間コードにコンパイルされたものは問題がないようです。

問題になるのは、Blogなどに掲載されている文字の状態のAppleScriptで、anythingについてはコンパイル(構文確認)時に気をつける必要がありそうです(メイン環境が10.14に移行していないのでちょっとまだ他人事)。

困ったときの古文書だより

一応、現代AppleScriptのルーツの資料とされている「AppleScriptLanguageGuide 1.3.7」(1999/5/5)のPDFを確認してみると、けっこう悩ましい内容が記述されています。

自分はanythingをclassか何かだと思っていたのですが、そこには定数(constants)だと書かれています。AppleScript version 1.3.7のころには、missing value(不定値)みたいな運用が行われていたようです。

AppleのEngineering Teamの見解は?

匿名希望の方がApple Engineering Teamに問い合わせしたところ「そんなマイナーな予約語は使うな」という返答であったとか。その一方でmacOS 10.14で「anything」の「list or list of string」への解釈化けが抑止されたりしているわけで、いまひとつわかりにくいというのが現状です。

Posted in OSA | Tagged 10.12savvy 10.13savvy 10.14savvy Script Debugger Script Editor | Leave a comment

Xcodeで最前面のAS sourceを構文確認

Posted on 3月 27, 2019 by Takaaki Naganoya

Xcodeで編集中のAppleScriptのプログラムを構文確認(コンパイルと表記されている、構文チェックと中間コードへの変換チェック、省略表記の展開など)するAppleScriptです。

本ScriptはXcode 9.2+macOS 10.12.6でテストしたものです。macOS 10.14+Xcode 10.2で実行したところ、file documentのnameに「– Edited」という入っていてはいけない文字列が入っていたり(それはWindowのtitleであってdocumentのnameじゃないだろう、、、、)、AppleScriptからXcodeを(データ書き込み)操作するとXcodeがクラッシュしたりと、まともに動作していない印象です。

Xcode 10.1+macOS 10.13.6で動かしたぶんには、Xcode上の表示は更新されていないものの、プロジェクト内の他のファイルをいったん表示させたあとに再度Scriptを表示させると書き換わっていました。Xcode 10.2+macOS 10.14.4の組み合わせでおかしな動きを行なっているようです。

XcodeのテキストエディタはAppleScriptの構文色分けを反映して表示しませんし、編集中にコンパイル(構文確認)するための機能がありません。インデント合わせやtellブロックやifブロックのネスティングの確認なども行えないため、記述のための最低限の機能を備えておらず、まともにプログラムを書くのであればScript Debuggerの併用は必須といえます。

先日のmacOS Nativeのミーティングにて、プレーンテキストエディタであるCotEditor上に記述したテキストのAppleScriptをコンパイル(構文確認)し、実際に実行して結果をCotEditor上の新規書類に出力するデモを実施。

このデモ内容は、はるかかなた昔から行なってきたものであり、CotEditorにかぎらず、あまねくどんなテキストエディタに対しても実行できるものです。macOS標準搭載のテキストエディットに対してすら同様のScriptを実行できます。

……と、振り返っていたときに、冒頭の「機能が致命的に足りない」Xcodeのテキストエディタのことを思い出したのです。

Xcodeのテキストエディタは(AppleScriptにとっては)致命的に機能が足りない欠陥品ですが、欠陥品には欠陥品なりの扱いをすればよいのではないかと気づきました。Xcodeに対してAppleScriptを実行することで、ソースを取得し、AppleScriptでAppleScriptをコンパイルし、Xcodeに書き戻してやればよいのではないか、と。

ずいぶんと昔に書いたXcode操作のScriptに若干のルーチンを足して動かしてみたところ、想像どおりうまく動きました。

ただし、少々のテストを行なっただけなので、実際にもっと使い込んでみる必要性を感じます。また、Xcode側が不可思議な挙動を行うため、Xcode上でAppleScriptを記述する場合には、依然としてScript Debugger必須です。

ちなみに、XcodeのAppleScriptサポート機能はいまひとつ不思議な挙動を行います。tellブロックでオブジェクト(documentとか)をくくり、その内側でオブジェクトに対する操作を行おうとするとエラー。tellブロックを正常に認識せず、tellブロック内でもそのオブジェクトへの参照を「of it」のように書く必要があります(実は、CotEditorもこのタイプ)。

最近、そのような不思議な挙動を行うアプリケーションがいくつか見られたため、「はいはい。君はof itが必要な人なんだね」と乗り切りましたが、これに気づかないと永遠にXcodeのまともなScriptは書けません。要注意です。

AppleScript名:最前面のAS sourceを構文確認.scptd
— Created 2018-05-19 by Takaaki Naganoya
— 2018 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "OSAKit"

property OSAScript : a reference to current application’s OSAScript
property OSALanguage : a reference to current application’s OSALanguage
property OSALanguageInstance : a reference to current application’s OSALanguageInstance

property targX : 1024 –View Width
property targY : 2048 –View Height

tell application "Xcode"
  –最前面のWindowの情報を取得
  
set winProp to properties of front window
  
set aDoc to document of winProp –Xcode のworkspace document(xcodeproj)
  
–> workspace document "WKWebViewDemo.xcodeproj" of application "Xcode"
  
  
set docProp to properties of aDoc
  
set xcodeDocPath to path of docProp
  
–> "/Users/me/Documents/Objective-C/WKWebViewDemo_MAC-master/WKWebViewDemo.xcodeproj"
  
  
set aFileDoc to name of winProp
  
–> "ViewController.m"
  
  
try
    set aDoc to file document aFileDoc
    
–> source document "ViewController.m" of application "Xcode"
  on error
    –Storyboard/Xib file/info.plist/Assetsなどを表示中の場合にはエラーになる
    
return false
  end try
  
  
set aDocPath to path of aDoc
  
–> "/Users/me/Documents/Objective-C/WKWebViewDemo_MAC-master/WKWebViewDemo/ViewController.m"
end tell

if aDocPath does not end with ".applescript" then
  display notification "Front Xcode document does not seem an AppleScriptObjC source"
  
return
end if

set theSource to read ((POSIX file aDocPath) as alias) as «class utf8»
set aRes to retComiledAppleScriptString(theSource, "AppleScript") of me

tell application "Xcode"
  tell aDoc
    set text of it to aRes
  end tell
end tell

–Compile AppleScript Source
on retComiledAppleScriptString(aStr as string, osalangName as string)
  set osaCon to current application’s OSAScriptController’s alloc()’s init()
  
set osaView to current application’s OSAScriptView’s alloc()’s initWithFrame:(current application’s NSMakeRect(0, 0, targX, targY))
  
osaCon’s setScriptView:osaView
  
osaCon’s setLanguage:(OSALanguage’s languageForName:osalangName)
  
osaView’s setString:aStr
  
osaCon’s compileScript:(missing value) –Compile(構文確認)
  
  
set aRes to (osaView’s |string|()) as string
  
return aRes
end retComiledAppleScriptString

★Click Here to Open This Script 

Posted in OSA Raw AppleEvent Code Text | Tagged 10.12savvy OSALanguage OSALanguageInstance OSAScript OSAScriptController OSAScriptView Xcode | 1 Comment

Finder上で選択中のAppleScriptの行数をカウントする

Posted on 2月 8, 2019 by Takaaki Naganoya

Finder上で選択中のAppleScript書類の行数や種別を取得して表UIで表示するAppleScriptです。

Myriad Tables Libを用いて結果を表UIで表示しています。

当初はAppleScript書類からソースを取得するのに/usr/bin/osadecompileコマンドを使っていたのですが、OSAKit経由で処理したほうが高速な印象があります。

–> Download Executable archive for macOS 10.14 (include Myriad Tables Lib)

macOS 10.14上で動作させるためには、Script Debugger上で本Scriptをオープンするか、本Scriptをバンドル形式で保存し、バンドル内(/Contents/Resources/Script Libraries フォルダ)にMyriad Tables Libを入れ、AppleScriptアプレットとして書き出す必要があります。

また、初回実行時には「セキュリティ」の承認ダイアログが表示されるため、これをOKする必要があります。AppleScriptアプレットはFinder上でアイコンをダブルクリックすると「Finder上で選択中のアイテム」を拾えないため(その瞬間、Finder上での選択アイテムはアプレット自身になってしまうため)、DockやmacOS標準装備のスクリプトメニューに登録して起動する必要があります。

AppleScript名:Finder上で選択中のAppleScriptの行数をカウントする v2.scpt
— Created 2019-02-04 by Takaaki Naganoya
— 2019 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "OSAKit"
use script "Myriad Tables Lib" version "1.0.8" –https://www.macosxautomation.com/applescript/apps/Script_Libs.html#MyriadTablesLib

property |NSURL| : a reference to current application’s |NSURL|
property NSArray : a reference to current application’s NSArray
property NSString : a reference to current application’s NSString
property OSAScript : a reference to current application’s OSAScript
property NSPredicate : a reference to current application’s NSPredicate
property NSURLIsPackageKey : a reference to current application’s NSURLIsPackageKey
property NSURLIsDirectoryKey : a reference to current application’s NSURLIsDirectoryKey
property NSURLTypeIdentifierKey : a reference to current application’s NSURLTypeIdentifierKey

–Finder上で選択中のファイルのうちAppleScript書類のみ抽出
tell application "Finder"
  set inFiles to selection as alias list
  
if inFiles = {} then return
end tell
set filRes1 to filterAliasListByUTIList(inFiles, {"com.apple.applescript.script", "com.apple.applescript.script-bundle"}) of me
if filRes1 = {} then return

–AppleScript書類の種別判定および行数カウント
set outList to {}
repeat with i in filRes1
  set aName to (NSString’s stringWithString:i)’s lastPathComponent() as string
  
set sInfo to detectScriptIsPureASorASOC(i) of me
  
set sText to scriptSource of getASsourceFor(i) of me
  
set sNum to count every paragraph of sText
  
set sUTI to retUTIfromPath(i) of me
  
if sUTI = "com.apple.applescript.script" then
    set sKind to "Script"
  else if sUTI = "com.apple.applescript.script-bundle" then
    set sKind to "Script Bundle"
  else
    set sKind to "Other"
  end if
  
  
set the end of outList to {aName, sInfo, sKind, sNum}
end repeat

–結果を表UIで表示する
tell script "Myriad Tables Lib"
  set aDispBounds to my makeInitialBounds:1200 withHeight:500
  
set theTable to make new table with data outList column headings {"script name", "ASOC", "Script Kind", "lines"} with title "AppleScript Line Count" with prompt "Your Selected Scripts" with row numbering and empty selection allowed –and can add and delete
  
modify table theTable initial position aDispBounds column widths pattern {1, 2, 3, 4} with hidden cancel button
  
modify columns in table theTable user date format {user format full, user format full} entry alignment align left
  (
display table theTable)
end tell

–Alias listから指定UTI Listに含まれるものをPOSIX pathのリストで返す
on filterAliasListByUTIList(aList as list, targUTIList as list)
  set outList to {}
  
repeat with i in targUTIList
    set j to contents of i
    
set aRes to filterAliasListByUTI(aList, j) of me
    
if aRes is not equal to {} then
      set outList to outList & aRes
    end if
  end repeat
  
return outList
end filterAliasListByUTIList

–Alias listから指定UTIに含まれるものをPOSIX pathのリストで返す
on filterAliasListByUTI(aList as list, targUTI)
  set newList to {}
  
repeat with i in aList
    set j to POSIX path of i
    
set tmpUTI to my retUTIfromPath(j)
    
set utiRes to my filterUTIList({tmpUTI}, targUTI)
    
if utiRes is not equal to {} then
      set the end of newList to j
    end if
  end repeat
  
return newList
end filterAliasListByUTI

–指定のPOSIX pathのファイルのUTIを求める
on retUTIfromPath(aPOSIXPath)
  set aURL to |NSURL|’s fileURLWithPath:aPOSIXPath
  
set {theResult, theValue} to aURL’s getResourceValue:(specifier) forKey:NSURLTypeIdentifierKey |error|:(missing value)
  
  
if theResult = true then
    return theValue as string
  else
    return theResult
  end if
end retUTIfromPath

–UTIリストが指定UTIに含まれているかどうか演算を行う
on filterUTIList(aUTIList, aUTIstr)
  set anArray to NSArray’s arrayWithArray:aUTIList
  
set aPred to NSPredicate’s predicateWithFormat_("SELF UTI-CONFORMS-TO %@", aUTIstr)
  
set bRes to (anArray’s filteredArrayUsingPredicate:aPred) as list
  
return bRes
end filterUTIList

on makeInitialBounds:(aTWidth as integer) withHeight:(aTHeight as integer)
  set aDispBounds to current application’s NSScreen’s mainScreen()’s frame()
  
if class of item 1 of aDispBounds = record then
    –macOS 10.10/10.11/10.12
    
set aWidth to (width of |size| of aDispBounds)
    
set aHeight to (height of |size| of aDispBounds)
  else
    –macOS 10.13 or later?
    
set aWidth to (item 1 of item 2 of aDispBounds)
    
set aHeight to (item 2 of item 2 of aDispBounds)
  end if
  
  
set xPos to (aWidth div 2) – (aTWidth div 2)
  
set yPos to (aHeight div 2) – (aTHeight div 2)
  
  
return {xPos, yPos, aTWidth, aTHeight}
end makeInitialBounds:withHeight:

–指定AppleScriptファイルがPure ASかASOCかを判定して返す
on detectScriptIsPureASorASOC(aFile)
  set sRes to getASsourceFor(aFile) of me
  
set sName to scriptKind of sRes –Name
  
set sText to scriptSource of sRes –Source
  
if sText = "" or sText = missing value then return missing value
  
  
if sName = "AppleScript" then
    if sText contains "use framework \"Foundation\"" then
      return true –ASOC
    else
      return false –Pure AppleScript
    end if
  else
    –JXAなど他のOSA言語の場合
    
return sName
  end if
end detectScriptIsPureASorASOC

–指定AppleScriptファイルのソースコードを取得する(実行専用Scriptからは取得できない)
on getASsourceFor(aPOSIXPath)
  set aURL to |NSURL|’s fileURLWithPath:(aPOSIXPath)
  
set theScript to current application’s OSAScript’s alloc()’s initWithContentsOfURL:aURL |error|:(missing value)
  
set scriptName to theScript’s |language|()’s |name|() as string
  
set theSource to theScript’s source() as text
  
return {scriptKind:scriptName, scriptSource:theSource}
end getASsourceFor

★Click Here to Open This Script 

Posted in file File path GUI OSA | Tagged 10.11savvy 10.12savvy 10.13savvy 10.14savvy NSArray NSPredicate NSString NSURL OSAScript | Leave a comment

Script Debuggerに必要な機能を追加する

Posted on 2月 8, 2019 by Takaaki Naganoya

毎日仕事で使っているAppleScript統合開発環境(IDE)、Late Night SoftwareのScript Debugger。大変リッチな機能を持っているものの、仕事で使えば使ったで不満が出てくるもので、機能を追加したくなってきました。

Script Debugger自体もScriptableなアプリケーションなので、AppleScriptを記述して機能を追加できます。ScriptからはApple純正のスクリプトエディタとまったく同じことができるわけではありませんが、ある程度まではコントロールが可能です。

Script DebuggerのAppleScript用語辞書はスクリプトの分析機能がスクリプトエディタよりも大幅に高機能であり、比較にもなりません。ただし、スクリプト書類の書式(style runs)を取得できないため、構文色分けを利用した構文要素への分解ができませんでした。変数名のみ置換するとかハンドラ名のリストアップするといった、スクリプトエディタで10年以上前から利用している機能が使えないわけです(このあたりの処理をスクリプトエディタに依存せずに実行できるようになったのは、ほんのつい最近のことです)。マインドマップ上に各ハンドラの呼び出し関係を図示するような処理も10年ぐらい前からやっていますが、それもScript Debugger上では行えませんでした。一長一短です。

Script Debuggerは独自のScript Menuを持っており、~/Library/Application Support/Script Debugger 7/Scripts/フォルダ内に(Script Debuggerをコントロールする)各種AppleScriptを入れておくとScript Debugger内のScript Menuから呼び出して実行できるようになっています。

ここで紹介するのは「includeしているライブラリをすべてオープンする」Scriptと、「includeしているライブラリのScriptをすべてクローズする」Scriptです。

open all Script Library

スクリプトバンドルのAppleScriptで、バンドル内にAppleScriptライブラリを含んでいる場合に、それらをScript Debuggerでオープンします。機能を細分化して記述している場合に、全Scriptをチェックする必要が生じるとこのようにすべてオープンして確認する必要があります。本来、共通部分をライブラリ化しておく必要があるわけですが、突発的にこういう作業が発生したもので。

Close Script Libraries

「open all Script Library」スクリプトでオープンしたライブラリをクローズするAppleScriptです。Script Debugger上でメインのAppleScriptを選んでおくと、そのScript中でincludeしている(use)AppleScript Librariesをクローズします。

Script Debuggerで一番不満なのは動的に生成したWindowやMenuなどのイベントを拾ってくれないことですが、ほかにも、useコマンドで利用しているAppleScript Librariesでバンドル内に含めていないものをチェックしてバンドル内に入れる機能がないことでしょうか(動作確認して客先に送ったあとで焦ることがたびたび)。そのあたりもぼちぼち、、、、メーカーにリクエストを出して実装を待つよりも、自分でScriptを組んだほうが早いので、、、

AppleScript名:open all Script Library
tell application "Script Debugger"
  tell document 1
    set libList to (used script library files)
    
set aWin to script window of it
    
–> {script window id 13269 of application "Script Debugger"}
  end tell
  
  
set targWin to contents of first item of aWin
  
  
repeat with i in libList
    set j to contents of i
    
set jj to j as alias
    
    
try
      open jj in window targWin
    end try
  end repeat
end tell

★Click Here to Open This Script 

AppleScript名:Close Script Libraries
tell application "Script Debugger"
  tell front document
    set libList to (used script library files)
    
if libList = {} then return –No AppleScript Libraries
  end tell
  
  
set dList to every document
  
repeat with i in dList
    tell i
      set fSpec to file spec
      
if fSpec is in libList then
        ignoring application responses
          close with saving
        end ignoring
      end if
    end tell
  end repeat
end tell

★Click Here to Open This Script 

Posted in file OSA | Tagged 10.11savvy 10.12savvy 10.13savvy Script Debugger | Leave a comment

ZipZapで指定アーカイブをメモリ上で展開して指定ファイルのみ取り出す

Posted on 1月 11, 2019 by Takaaki Naganoya

オープンソースのZipZapをCocoa Framework化したものを呼び出して、指定のZipアーカイブをメモリ上で展開し、指定ファイルの内容を取り出すAppleScriptです。

–> ZipZap.framework(To ~/Library/Frameworks/)

ZipアーカイブでAppleScriptを固めておいて、XcodeのAppleScriptアプリケーションのプロジェクト中に入れておき、指定ファイルのScriptをZipアーカイブから取り出して実行するときに使っています。

ZipZapはXcode Projectに入れてよし、Cocoa Frameworkに入れて呼び出してよし、と自分にとってたいへんに使い勝手のよい部品であり、重要なパーツになっています。

AppleScript名:ZipZapで指定アーカイブをメモリ上で展開して指定ファイルのみ取り出す
— Created 2019-01-11 by Takaaki Naganoya
— 2019 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "ZipZap" –https://github.com/pixelglow/ZipZap
use framework "OSAKit"
use BPlus : script "BridgePlus" –https://www.macosxautomation.com/applescript/apps/BridgePlus.html

property |NSURL| : a reference to current application’s |NSURL|
property ZZArchive : a reference to current application’s ZZArchive
property OSAScript : a reference to current application’s OSAScript

set anArchive to POSIX path of (choose file of type {"public.zip-archive"})
set aRes to extractArchiveAndPickupAFile(anArchive, "", "02_script.scpt") of me

on extractArchiveAndPickupAFile(aPath, aPass, aTargFileName)
  set oldArchive to ZZArchive’s archiveWithURL:(|NSURL|’s fileURLWithPath:aPath) |error|:(missing value)
  
set aList to oldArchive’s entries() as list
  
  set outList to {}
  
  repeat with i in aList
    set encF to i’s encrypted() as boolean
    
set aFileName to (i’s fileName())
    
    if (aFileName as string) = aTargFileName then
      
      set aExt to (aFileName’s pathExtension()) as string
      
set aUTI to my retFileFormatUTI(aExt)
      
set aData to (i’s newDataWithError:(missing value)) –Uncompressed raw data
      
      if aData = missing value then
        set aData to (i’s newDataWithPassword:(aPass) |error|:(missing value))
        
if aData is equal to (missing value) then
          return false
        end if
      end if
      
      if aUTI = "public.plain-text" then
        –Plain Text
        
set aStr to (NSString’s alloc()’s initWithData:aData encoding:(NSUTF8StringEncoding)) as string
        
      else if aUTI = "com.apple.applescript.script" then
        –AppleScript .scpt file
        
set aScript to (OSAScript’s alloc()’s initWithCompiledData:aData |error|:(missing value))
        
set aStr to (aScript’s source()) as string
        
      end if
      
return aStr
      
    end if
  end repeat
  
end extractArchiveAndPickupAFile

on retFileFormatUTI(aExt as string)
  tell script "BridgePlus"
    load framework
    
return (current application’s SMSForder’s UTIForExtension:aExt) as string
  end tell
end retFileFormatUTI

★Click Here to Open This Script 

Posted in file File path OSA Text UTI | Tagged 10.11savvy 10.12savvy 10.13savvy 10.14savvy | Leave a comment

【基礎】AppleScriptの実行を(操作により)中断する

Posted on 10月 30, 2018 by Takaaki Naganoya

AppleScriptの実行を途中で任意に停止したい、という場合があります。そのための方法についてまとめておきました。

# Blog消失前の投稿を再構成して「たぶんこんな内容」と推測して投稿したものです

実行を中断させる方法はいくつか存在します。ただし、そのためには「何によってAppleScriptが実行されているか」、つまり「ランタイム環境が何なのか?」を明らかにする必要があります。

AppleScriptのランタイム環境は、つきつめると数種類「しか」ないわけですが、そのランタイム環境を呼び出している側のアプリケーションにどの程度の制約を課されているか、という要素も加わってきます。

システムのあちらこちらに存在しているAppleScriptのランタイム環境のうち、ユーザーに近い部分のものについて述べることにしましょう。

ランタイム環境が「スクリプトエディタ」の場合の止め方

スクリプトエディタ上で実行中のAppleScriptは、Command-.(ピリオド)で停止できるようになっています。

ただし、すでに操作対象のアプリケーション側に制御が移っている場合には、アプリケーション側の処理が終わるまで待たされますし、アプリケーションが最前面にくるように(activate)AppleScriptが書かれていた場合には、スクリプトエディタに対して停止のキーボードショートカットを送ることは困難です。

最終的には、Command-Option-Escapeで実行中のプロセス一覧を表示させて、スクリプトエディタを強制終了させることになります。

もちろん、Terminal.app上で、Script Editor.appのプロセス番号を調べて、

% kill -7 xxx

などと野蛮な止め方をしてもよいでしょう。AppleScriptの実行を野蛮な方法で停止しても、AppleScriptの内容が壊れることはまずありません。ただし、処理していたデータは中途半端な状態のままになってしまいます。こうした処理を行う場合には、くれぐれも元データを保持しておいて、AppleScriptによる処理が失敗したり途中で停止するようなことになっても、再度実行できるようにしておきましょう。

ランタイム環境がアプレットの場合の止め方

個人的に、AppleScriptアプレットというランタイム環境はスクリプトエディタ上と挙動が変わってくるので、あまり好きではありません。それでも、タイマー割り込みやドラッグ&ドロップなどの機能を使う場合にはアプレット(ドロップレット)として保存する必要が出てきます。

アプレットの場合も、スクリプトエディタ同様Command-.(ピリオド)で止めることになりますが、たいてい止まらないのでCommand-Option-Escapeによる強制終了、あるいはターミナルから実行中のアプレットのプロセスIDを調べて強制終了、でもよいでしょう。

ランタイム環境がスクリプトメニューの場合の止め方

スクリプトメニューをどのプログラムが受け持っているか、Mac OS Xの歴史を振り返ると、いろいろ移り変わりがありました。実行するアプリケーションが単独で存在していたり、System Eventsが受け持っていたり、osascriptを呼び出していたり、ふたたび単体のアプリケーションに戻ったり。OSのバージョンを限定して話をすると、macOS 10.10〜10.13の環境ではosascriptによって実行されてきました。

スクリプトメニューからAppleScriptを実行させると、メニューに回転する歯車アイコンが表示されます。この歯車アイコンをクリックすると実行中のAppleScript一覧が表示され(複数のScriptを並行して同時に実行させることもできます)各Scriptの右下の×ボタンを押すと停止できます。

これでも止まらない場合には、Terminalからosascriptのプロセスをkillすれば大丈夫です。

macOS 10.14ではスクリプトメニューが「スクリプトメニュー」という別のアプリケーションとして実装されたので、macOS 10.14上のスクリプトメニューのランタイム環境は「スクリプトメニュー」です。Command-Option-Escapeでは終了できないので、ターミナルから「スクリプトメニュー」のプロセスIDを調べてkillすることになります。

その他の止め方

Xcode上でAppleScriptによるGUIアプリケーションを作成し、InDesignやIllustratorなどのアプリケーションを操作する処理を実行。この外部アプリケーションの操作を行う処理を止めたいといった場合もあります。

AppleScript Studioの頃とは異なり、最近のAppleScriptObjCによるGUIアプリケーション作成時には、GUIアプリケーション側と外部アプリケーション操作側は完全に分離され、後者についてはXcode上では編集すらできません。データの受け渡しはuser defaults経由で行ったりしています。

難易度の低いやり方は、外部アプリ制御側Scriptで、「処理ループ内で何らかのシグナルを監視する」というものです。特定フォルダの有無でも「メッセージ」アプリケーションのステータスメッセージでも特定Webサーバー上の特定URLのファイルでもよいのですが、それらが存在した場合には停止、というプログラム自体を組んでおきます。デスクトップ上に「Stop」という名前のフォルダが存在していたら終了、というあたりがわかりやすくて簡単な実装例でしょう。

難易度の高いやり方は、外部アプリ制御Scriptを、メモリ上に作成したOSAScriptView上で実行し、停止時にはOSAScriptControllerにstopScript:メソッドを実行するというものです。もちろん、外部アプリ制御Scriptはアプリケーションバンドル内に暗号化したファイルに保存しておき、実行時に復号化してOSAScriptViewにロードすることになります。ユーザーからの停止の仕組みを受け取るのは、Shiftキーなどのキースキャンを定期的に行うことで実現できます。

難易度の高い方が柔軟に止められますが、おすすめは難易度の低いほうです。

Posted in OSA System | 1 Comment

ZipZap frameworkを使ってZipアーカイブ内の情報を取得しファイルタイプごとに対応出力

Posted on 9月 29, 2018 by Takaaki Naganoya

オープンソースのZipZap frameworkを用いて、指定Zipアーカイブ内の情報を取得し、ファイルタイプごとに対応した出力を行うAppleScriptです。

–> ZipZap.framework(To ~/Library/Frameworks/)

客観的に動作内容を書くとわかりにくいですが、「目的」を書くと非常にわかりやすい部品です。

「バンドル内にパスワード付きのZipアーカイブ化したAppleScript書類を入れておいて、実行時にアーカイブからAppleScriptのソースを取り出して実行する」

というのが、その用途です。

プレーンテキストと画像を取り出せるような記述になっていますが、それらはあくまでも実験用で、AppleScript書類のソースを取り出すのが本来の目的です。

AppleScriptでGUIアプリケーションを作成したときに、GUIまわりは普通にXcode上で記述して(あるいは、外部エディタ上で記述して)おきますが、外部のアプリケーションをコントロールするコードは、実行専用の.scpt形式でかつ書き込み禁止状態にしてバンドル内に入れておいたりします(SandBox対応のため)。

ただ、さまざまな要求を満たすようにGUIアプリケーション操作用のScriptを呼び出そうとすると、load scriptで読み込んで実行させていたのでは、都合がよくない場合があります(何らかのキーを長押しすると実行を停止できるとか、システム内の別の要素……たとえばCPUの温度が上がりすぎたら停止させるとか)。

load scriptで実行すると、

(1)途中で実行停止しにくい
(2)セキュリティ上の制約がきつい(とくにGUI Scriptingまわり)
(3)スクリプトエディタ上で動かしていた時と挙動が変わる箇所がある(Finder上のselectionを取得していた場合とか)

といった問題がありますが、OSAScriptView上にAppleScriptのソースを展開して実行すると、これらの問題を解決できる一方、ソースが見える形式でアプリケーションバンドル内に入れるのはためらわれます。

その問題を解決するために書いたものです。展開したデータをファイル出力せず、すべて変数上で(オンメモリで)処理できるので都合がいいです。

Mac App Storeで販売するアプリケーションでこの部品を使ったことはありませんが、客先に納品するアプリケーションでは使えるといったところでしょうか。ここまで手の込んだプログラムだとリジェクトできないとは思っています(もっとレベルの低い指摘しか来ないので)。

AppleScript名:ZipZap frameworkを使ってZipアーカイブ内の情報を取得してファイルタイプごとに対応出力 v2
— Created 2018-09-28 by Takaaki Naganoya
— 2018 Piyomaru Software
use AppleScript version "2.5"
use scripting additions
use framework "Foundation"
use framework "OSAKit"
use framework "ZipZap" –https://github.com/pixelglow/zipzap
use bPlus : script "BridgePlus" –https://www.macosxautomation.com/applescript/apps/BridgePlus.html

property |NSURL| : a reference to current application’s |NSURL|
property NSArray : a reference to current application’s NSArray
property NSString : a reference to current application’s NSString
property NSImage : a reference to current application’s NSImage
property ZZArchive : a reference to current application’s ZZArchive
property OSAScript : a reference to current application’s OSAScript
property NSPredicate : a reference to current application’s NSPredicate
property NSUTF8StringEncoding : a reference to current application’s NSUTF8StringEncoding
property NSURLTypeIdentifierKey : a reference to current application’s NSURLTypeIdentifierKey

set aPassword to "piyomarusoftware"
set aPath to POSIX path of (choose file of type {"public.zip-archive"})
set aList to extractArchive(aPath, aPassword) of me

on extractArchive(aPath, aPass)
  set oldArchive to ZZArchive’s archiveWithURL:(|NSURL|’s fileURLWithPath:aPath) |error|:(missing value)
  
set aList to oldArchive’s entries() as list
  
  
set outList to {}
  
  
repeat with i in aList
    set encF to i’s encrypted() as boolean
    
    
set aFileName to i’s fileName()
    
    
if (aFileName as string) does not start with "__MACOSX/" then
      set aExt to (aFileName’s pathExtension()) as string
      
set aUTI to my retFileFormatUTI(aExt)
      
set aData to (i’s newDataWithError:(missing value)) –Uncompressed raw data
      
      
if aData = missing value then
        set aData to (i’s newDataWithPassword:(aPass) |error|:(missing value))
        
if aData is equal to (missing value) then
          error "Internal archive error in extracting"
        end if
      end if
      
      
if aUTI = "public.plain-text" then
        –Plain Text
        
set aStr to (NSString’s alloc()’s initWithData:aData encoding:(NSUTF8StringEncoding)) as string
        
      else if aUTI = "com.apple.applescript.script" then
        –AppleScript .scpt file
        
set aScript to (OSAScript’s alloc()’s initWithCompiledData:aData |error|:(missing value))
        
set aStr to (aScript’s source()) as string
        
      else if (my filterUTIList({aUTI}, "public.image")) is not equal to {} then
        –Various Images
        
set aStr to (NSImage’s alloc()’s initWithData:aData)
        
      end if
      
      
set the end of outList to aStr
    end if
  end repeat
  
  
return outList
end extractArchive

on retFileFormatUTI(aExt as string)
  tell script "BridgePlus"
    load framework
    
return (current application’s SMSForder’s UTIForExtension:aExt) as string
  end tell
end retFileFormatUTI

–UTIリストが指定UTIに含まれているかどうか演算を行う
on filterUTIList(aUTIList, aUTIstr)
  set anArray to NSArray’s arrayWithArray:aUTIList
  
set aPred to NSPredicate’s predicateWithFormat_("SELF UTI-CONFORMS-TO %@", aUTIstr)
  
set bRes to (anArray’s filteredArrayUsingPredicate:aPred) as list
  
return bRes
end filterUTIList

★Click Here to Open This Script 

Posted in file OSA Text URL UTI | Tagged 10.11savvy 10.12savvy 10.13savvy NSArray NSImage NSPredicate NSString NSURL NSURLTypeIdentifierKey NSUTF8StringEncoding OSAScript ZZArchive | Leave a comment

WordPressの指定IDの記事にリンクされているapplescriptからCocoa Classのproperty宣言を抽出 v3

Posted on 8月 5, 2018 by Takaaki Naganoya

本BlogのようなWordPressで運用されており、AppleScriptのURLリンクを記事に埋め込んでいるWordPressに対して、XML-RPC経由で指定IDの記事本文を取得し、埋め込まれているURLリンクからAppleScriptのソースコードを取得して、メモリー上でコンパイルして書式つきテキストに変換し、AppleScript構文書式をもとにpropertyラベルを抽出、そのうちCocoa Classのみをリストで取得するAppleScriptです。

本Blogに投稿した記事から宣言しているCocoa Classを抽出し、自動でタグ付けするために準備したものです。1記事に対して複数のAppleScriptが掲載されている場合にも対応しています。

HTMLReader.frameworkを用いてBlog本文からのリンク抽出、リンクURL抽出を行っています。

–> HTMLReader.framework(To ~/Library/Frameworks/)

本Sample Scriptで指定したIDの記事のproperty部分はこのようになっており、

本Scriptの実行によって抽出されたCocoa Class(単なる変数的なproperty項目や、Enumは対象外のため排除)は、

–> {“NSString”, “NSArray”, “OSAScript”, “NSPredicate”, “OSALanguage”, “NSDictionary”, “OSALanguageInstance”, “NSBundle”, “NSUnarchiver”}

のようになります。自分の環境でMacBook Proを有線ネットワーク接続した状態で、3.3〜3.4秒程度かかっています。大量の記事を処理する場合には本AppleScriptの並列処理を行うと処理時間の大幅な短縮が期待できます(MacのCPUがサーマルスロットリングで速度低下しなければ)。

また、負荷が集中している特定コアの動作周波数を上げ、他のコアの動作周波数を落とすTurbo Boostが有効な状態で並列処理を実行すると、並列処理を行う意義そのものが低下してしまうため、Turbo-Boost-Switcherのようなツールの併用が必要と思われます。

AppleScript名:WordPressの指定IDの記事にリンクされているapplescriptからCocoa Classのproperty宣言を抽出 v3
— Created 2018-07-30 by Takaaki Naganoya
— Modified 2018-08-05 by Takaaki Naganoya
— 2018 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"
use framework "OSAKit"
use framework "HTMLReader" –https://github.com/nolanw/HTMLReader

property |NSURL| : a reference to current application’s |NSURL|
property NSArray : a reference to current application’s NSArray
property NSString : a reference to current application’s NSString
property NSBundle : a reference to current application’s NSBundle
property NSThread : a reference to current application’s NSThread
property OSAScript : a reference to current application’s OSAScript
property NSPredicate : a reference to current application’s NSPredicate
property NSTextView : a reference to current application’s NSTextView
property NSDictionary : a reference to current application’s NSDictionary
property NSUnarchiver : a reference to current application’s NSUnarchiver
property OSALanguage : a reference to current application’s OSALanguage
property OSAScriptView : a reference to current application’s OSAScriptView
property NSMutableArray : a reference to current application’s NSMutableArray
property OSAScriptController : a reference to current application’s OSAScriptController
property NSMutableDictionary : a reference to current application’s NSMutableDictionary
property OSALanguageInstance : a reference to current application’s OSALanguageInstance
property NSUTF8StringEncoding : a reference to current application’s NSUTF8StringEncoding

set postID to 3864
set {myUser, myPass} to getAcountData() of me
set aURL to "http://piyocast.com/as/xmlrpc.php"
set cocoaClassList to getCocoaPropListFromPost(aURL, postID, myUser, myPass) of me
–>  {"NSString", "NSBundle", "NSPredicate", "NSDictionary", "NSMutableArray", "NSMutableDictionary"}

–指定Blogの指定IDの記事にURLリンクされているAppleScriptから、Cocoa Classのpropertyのみ取得する
on getCocoaPropListFromPost(aURL, postID, myUser, myPass)
  –AppleScriptの構文色分け設定ファイルを読み込んで、重複色のチェックを実施  
  
set cList to getAppleScriptSourceColors() of me
  
set cRes to chkASLexicalFormatColorConfliction(cList) of me –構文色分けの重複色チェック
  
if cRes = false then error "There is some duplicate(s) color among AppleScript’s lexical color settings"
  
  
–WordPressの指定Post IDの記事を取得してリンクされているURLからURL Schemeでフィルタして、リンクされているAppleScriptのソースを取得
  
set aScheme to "applescript://"
  
set sourceList to getASSouceLinkedInWordPressPost(postID, aURL, aScheme, myUser, myPass) of me
  
  
–AppleScriptのソースをRAM上でコンパイル(構文確認)して、構文色分けしたRTFを取得。RTFの書式情報をparseしてattribute runsと同様のrecordを生成
  
–構文色分けをもとにproperty項目を抽出し、Cocoa Classに該当するもののみを抽出
  
set outList to {}
  
repeat with i in sourceList
    set j to contents of i
    
set anAttrStr to compileASandReturnAttributedString(j) of me
    
set attrRes to getAttributeRunsFromAttrString(anAttrStr) of me
    
set propNames to getPropertyNamesCocoaOnly(cList, attrRes) of me
    
    
if propNames is not equal to {} then
      set outList to outList & propNames
    end if
  end repeat
  
  
–1D Listのユニーク化(重複要素の排除)
  
set aArray to NSArray’s arrayWithArray:outList
  
set bArray to aArray’s valueForKeyPath:"@distinctUnionOfObjects.self"
  
set bList to bArray as list of string or string –as anything
  
  
return bList
end getCocoaPropListFromPost

–Property名称を取得する
on getPropertyNamesCocoaOnly(cList, aRec)
  script spdHnd
    property aRec : {}
  end script
  
  
set (aRec of spdHnd) to aRec
  
  
set targAttr to contents of item 7 of cList –ハンドラあるいは変数
  
set tmpCoStr to ((redValue of targAttr) as string) & " " & ((greenValue of targAttr) as string) & " " & ((blueValue of targAttr) as string)
  
  
set ontoColItem to contents of item 3 of cList –スクリプティング予約語(on/to)
  
set ontoCoStr to ((redValue of ontoColItem) as string) & " " & ((greenValue of ontoColItem) as string) & " " & ((blueValue of ontoColItem) as string)
  
  
  
–変数あるいはハンドラ名称をリストアップ(variables & handler)
  
set tmp1Array to NSArray’s arrayWithArray:(aRec of spdHnd)
  
set thePred0 to NSPredicate’s predicateWithFormat_("colorStr == %@", tmpCoStr)
  
set dArray to (tmp1Array’s filteredArrayUsingPredicate:thePred0) as list
  
  
–改行を含むデータをリストアップ(text data contains return)
  
set thePred1 to NSPredicate’s predicateWithFormat_("stringVal CONTAINS %@", return)
  
set eArray to ((tmp1Array’s filteredArrayUsingPredicate:thePred1)’s valueForKeyPath:"itemIndex") as list
  
  
set the beginning of eArray to 0 –ハンドラ宣言部がTopに来る場合に備える
  
  
–"property"(プロパティ宣言)の項目をリストアップ 文字と色で抽出
  
set thePred2 to NSPredicate’s predicateWithFormat_("stringVal == %@ && colorStr == %@ ", "property", ontoCoStr)
  
set fArray to ((tmp1Array’s filteredArrayUsingPredicate:thePred2)’s valueForKeyPath:"itemIndex") as list
  
  
set handlerList to {}
  
  
–property ではじまるハンドラの抽出
  
repeat with i in eArray –改行を含むテキストのアイテム番号リスト
    set j to (contents of i) as integer
    
repeat with ii in fArray –"on"の項目リスト
      set jj to (contents of ii) as integer
      
      
set handlerStr to missing value
      
      
if (j + 1) = jj then
        set handlerStr to stringVal of (item (jj + 2) of ((aRec of spdHnd) as list))
      else if (j + 2) = jj then
        set handlerStr to stringVal of (item (jj + 2) of ((aRec of spdHnd) as list))
      end if
      
      
set tmpStr to repChar(handlerStr, "|", "") of me
      
      
if tmpStr is not in {"error", missing value} and tmpStr is not in handlerList then
        –抽出したProperty宣言がCocoa Classのものかどうか判定
        
if searchClassInFrameworks(tmpStr) of me is not equal to false then
          set the end of handlerList to tmpStr
        end if
      end if
      
    end repeat
  end repeat
  
  
return handlerList
end getPropertyNamesCocoaOnly

–RAM上にスクリプトエディタと同じ部品を組み立て(非表示)、AppleScriptのソーステキストからObjectを生成し、Attributed Stringデータを返す
on compileASandReturnAttributedString(theSource as string)
  set targX to 1024 –View Width
  
set targY to 2048 –View Height
  
  
set osaCon to current application’s OSAScriptController’s alloc()’s init()
  
set osaView to current application’s OSAScriptView’s alloc()’s initWithFrame:(current application’s NSMakeRect(0, 0, targX, targY))
  
  
set resView to NSTextView’s alloc()’s initWithFrame:(current application’s NSMakeRect(0, 0, targX, targY))
  
resView’s setRichText:true
  
resView’s useAllLigatures:true
  
  
osaCon’s setScriptView:osaView
  
osaCon’s setLanguage:(OSALanguage’s languageForName:"AppleScript")
  
osaCon’s setResultView:resView
  
  
osaView’s setString:theSource
  
osaCon’s compileScript:(missing value) –Compile(構文確認)
  
  
set aRes to (osaView’s attributedString())
  
  
return aRes
end compileASandReturnAttributedString

–Attributed StringをDictionary化
on getAttributeRunsFromAttrString(theStyledText)
  script aSpd
    property styleList : {}
  end script
  
  
set (styleList of aSpd) to {} —for output
  
  
set thePureString to theStyledText’s |string|() –pure string from theStyledText
  
  
set theLength to theStyledText’s |length|()
  
set startIndex to 0
  
set itemCount to 1
  
  
repeat until (startIndex = theLength)
    set {theAtts, theRange} to theStyledText’s attributesAtIndex:startIndex longestEffectiveRange:(reference) inRange:{startIndex, theLength – startIndex}
    
    
–String  
    
set aText to (thePureString’s substringWithRange:theRange) as string
    
    
–Color
    
set aColor to (theAtts’s valueForKeyPath:"NSColor")
    
if aColor is not equal to missing value then
      set aSpace to aColor’s colorSpace()
      
      
set aRed to (aColor’s redComponent()) * 255
      
set aGreen to (aColor’s greenComponent()) * 255
      
set aBlue to (aColor’s blueComponent()) * 255
      
      
set colList to {aRed as integer, aGreen as integer, aBlue as integer} –for comparison
      
set colStrForFind to (aRed as integer as string) & " " & (aGreen as integer as string) & " " & (aBlue as integer as string) –for filtering
    else
      set colList to {0, 0, 0}
      
set colStrForFind to "0 0 0"
    end if
    
    
–Font
    
set aFont to (theAtts’s valueForKeyPath:"NSFont")
    
if aFont is not equal to missing value then
      set aDFontName to aFont’s displayName()
      
set aDFontSize to aFont’s pointSize()
    end if
    
    
set the end of (styleList of aSpd) to {stringVal:aText, colorStr:colStrForFind, colorVal:colList, fontName:aDFontName as string, fontSize:aDFontSize, itemIndex:itemCount}
    
set startIndex to current application’s NSMaxRange(theRange)
    
    
set itemCount to itemCount + 1
  end repeat
  
  
return (styleList of aSpd)
  
end getAttributeRunsFromAttrString

–指定クラスがいずれかのCocoa Frameworkに所属しているかを検索
on searchClassInFrameworks(aTarget)
  set aClass to current application’s NSClassFromString(aTarget)
  
if aClass = missing value then return false
  
set theComponenents to (NSBundle’s bundleForClass:aClass)’s bundleURL’s pathComponents()
  
set thePred to NSPredicate’s predicateWithFormat:"pathExtension == ’framework’"
  
set aRes to (theComponenents’s filteredArrayUsingPredicate:thePred)’s firstObject() as list of string or string
  
return aRes
end searchClassInFrameworks

–指定Post IDのWordPress記事から、指定SchemeのURLを抽出し、AS Sourceをdecodeしてproperty行のみ抽出
on getASSouceLinkedInWordPressPost(postID, aURL, aScheme, myUser, myPass)
  –call xmlrpc命令に対するURLの間接指定を有効にするために、AppleScriptの構文解釈機能をダミーURLでだます
  
using terms from application "http://piyocast.com/as/xmlrpc.php" –URLと判定されればなんでもいい
    tell application aURL
      set wRes to (call xmlrpc {method name:"wp.getPost", parameters:{"1", myUser, myPass, postID as string}})
    end tell
  end using terms from
  
  
set aBody to post_content of wRes –Blog本文
  
  
–記事中でリンクしているURLを取得し、指定のURL Schemeでフィルタする
  
set urlList to filterURLLinksByScheme(aBody, aScheme) of me
  
  
set propList to {}
  
  
repeat with i in urlList
    set j to contents of i
    
set urlRec to parseQueryDictFromURLString(j) of me
    
set tmpScript to (urlRec’s |script|) as string –Get AppleScript Source
    
    
set propList to propList & tmpScript
  end repeat
  
  
return propList
end getASSouceLinkedInWordPressPost

on parseQueryDictFromURLString(aURLStr as string)
  if aURLStr = "" then error "No URL String"
  
  
set aURL to |NSURL|’s URLWithString:aURLStr
  
set aQuery to aURL’s query() –Get Query string part from URL
  
if aQuery’s |length|() = 0 then return false
  
  
set aDict to NSMutableDictionary’s alloc()’s init()
  
set aParamList to (aQuery’s componentsSeparatedByString:"&") as list
  
  
repeat with i in aParamList
    set j to contents of i
    
if length of j > 0 then
      set tmpStr to (NSString’s stringWithString:j)
      
set eList to (tmpStr’s componentsSeparatedByString:"=")
      
set anElement to (eList’s firstObject()’s stringByReplacingPercentEscapesUsingEncoding:(NSUTF8StringEncoding))
      
set aValStr to (eList’s lastObject()’s stringByReplacingPercentEscapesUsingEncoding:(NSUTF8StringEncoding))
      (
aDict’s setObject:aValStr forKey:anElement)
    end if
  end repeat
  
  
return aDict
end parseQueryDictFromURLString

–指定のHTML文字列から、Link URLを抽出し、schemeで再抽出する
on filterURLLinksByScheme(aBody, aScheme)
  set conType to "text/html"
  
  
–HTML文字列をいったんNSDataにしているのは、HTMLReader.frameworkの仕様のため
  
set aData to (current application’s NSString’s stringWithString:aBody)’s dataUsingEncoding:(current application’s NSUTF8StringEncoding)
  
set aHTML to current application’s HTMLDocument’s documentWithData:aData contentTypeHeader:conType
  
  
set aTextArray to ((aHTML’s nodesMatchingSelector:"a")’s textContent) as list –リンク文字
  
set aLinkList to ((aHTML’s nodesMatchingSelector:"a")’s attributes’s valueForKeyPath:"href") as list –URL文字列
  
  
set outList to {}
  
repeat with i in aLinkList
    set j to contents of i
    
if j begins with aScheme then
      set the end of outList to j
    end if
  end repeat
  
  
return outList
end filterURLLinksByScheme

–文字置換
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

–AppleScriptの構文色分けのカラー値をRGBで取得する
on getAppleScriptSourceColors()
  — get the plist info as a dictionary
  
set thePath to NSString’s stringWithString:"~/Library/Preferences/com.apple.applescript.plist"
  
set thePath to thePath’s stringByExpandingTildeInPath()
  
set theInfo to NSDictionary’s dictionaryWithContentsOfFile:thePath
  
  
— extract relevant part and loop through
  
set theArray to (theInfo’s valueForKey:"AppleScriptSourceAttributes") as list
  
  
set colList to {}
  
  
repeat with i from 1 to count of theArray
    set anEntry to item i of theArray
    
    
set colorData to NSColor of anEntry
    
set theColor to (NSUnarchiver’s unarchiveObjectWithData:colorData)
    
    
set {rVal, gVal, bVal} to retColListFromNSColor(theColor, 255) of me
    
    
set fontData to NSFont of anEntry
    
set theFont to (NSUnarchiver’s unarchiveObjectWithData:fontData)
    
    
set aFontName to theFont’s displayName() as text
    
set aFontSize to theFont’s pointSize()
    
    
set aColRec to {redValue:rVal, greenValue:gVal, blueValue:bVal, fontName:aFontName, fontSize:aFontSize}
    
    
set the end of colList to aColRec
  end repeat
  
  
return colList
end getAppleScriptSourceColors

–NSColorからRGBの値を取り出す
on retColListFromNSColor(aCol, aMAX as integer)
  set aRed to round ((aCol’s redComponent()) * aMAX) rounding as taught in school
  
set aGreen to round ((aCol’s greenComponent()) * aMAX) rounding as taught in school
  
set aBlue to round ((aCol’s blueComponent()) * aMAX) rounding as taught in school
  
  
if aRed > aMAX then set aRed to aMAX
  
if aGreen > aMAX then set aGreen to aMAX
  
if aBlue > aMAX then set aBlue to aMAX
  
  
return {aRed, aGreen, aBlue}
end retColListFromNSColor

–AS書式で配色に重複がないかどうかチェック
on chkASLexicalFormatColorConfliction(aList)
  set anArray to current application’s NSArray’s arrayWithArray:aList
  
set bList to (anArray’s valueForKeyPath:"redValue.stringValue") as list
  
set cList to (anArray’s valueForKeyPath:"greenValue.stringValue") as list
  
set dList to (anArray’s valueForKeyPath:"blueValue.stringValue") as list
  
  
set colStrList to {}
  
repeat with i from 1 to (length of bList)
    set bItem to contents of item i of bList
    
set cItem to contents of item i of cList
    
set dItem to contents of item i of dList
    
set the end of colStrList to bItem & " " & cItem & " " & dItem
  end repeat
  
  
set aRes to returnDuplicatesOnly(colStrList) of me
  
if aRes is equal to {} then
    return true –重複が存在しなかった場合
  else
    return false –重複があった場合
  end if
end chkASLexicalFormatColorConfliction

on returnDuplicatesOnly(aList as list)
  set aSet to current application’s NSCountedSet’s alloc()’s initWithArray:aList
  
set bList to (aSet’s allObjects()) as list
  
  
set dupList to {}
  
repeat with i in bList
    set aRes to (aSet’s countForObject:i)
    
if aRes > 1 then
      set the end of dupList to (contents of i)
    end if
  end repeat
  
  
return dupList
end returnDuplicatesOnly

on getAcountData()
  return {"xxxxxxxx_xx", "XXXXXXXXXXXXXXXXXXXXXXXX"} –user name, password
end getAcountData

★Click Here to Open This Script 

Posted in list OSA RTF Text URL XML-RPC | Tagged 10.11savvy 10.12savvy 10.13savvy NSArray NSBundle NSDictionary NSMutableArray NSMutableDictionary NSPredicate NSString NSTextView NSThread NSUnarchiver OSALanguage OSALanguageInstance OSAScript OSAScriptController OSAScriptView | Leave a comment

miでAppleScriptを実行して結果を新規Windowで返す

Posted on 4月 26, 2018 by Takaaki Naganoya

テキストエディタ「mi」v3.0のドキュメントに記述してあるAppleScriptをコンパイル(構文確認)して元の書類に書き戻し、結果を新規Windowに表示するAppleScriptです。

–> Watch Demo

とくに、miでなくても他のテキストエディタでも同様の動作は可能です。

AppleScript名:miでAppleScriptを実行して結果を新規Windowで返す
— Created 2018-04-24 by Takaaki Naganoya
— 2018 Piyomaru Software
use AppleScript version "2.5"
use scripting additions
use framework "Foundation"
use framework "OSAKit"

property NSThread : a reference to current application’s NSThread
property OSAScript : a reference to current application’s OSAScript
property NSTextView : a reference to current application’s NSTextView
property OSALanguage : a reference to current application’s OSALanguage
property OSAScriptView : a reference to current application’s OSAScriptView
property OSAScriptController : a reference to current application’s OSAScriptController
property OSALanguageInstance : a reference to current application’s OSALanguageInstance

property theResult : "" –result

set my theResult to ""

tell application "mi"
  tell front document
    if mode is not equal to "AppleScript" then return
    
set theSource to content
  end tell
end tell

set asSource to my compileASandReturnString:theSource
my performSelectorOnMainThread:"execASandReturnString:" withObject:theSource waitUntilDone:true

tell application "mi"
  tell front document
    set content to asSource
  end tell
  
  
set newDoc to make new document
  
tell newDoc
    set mode to "AppleScript"
    
set content to theResult
  end tell
end tell

on execASandReturnString:(theSource as string)
  set targX to 1024 –View Width
  
set targY to 2048 –View Height
  
  
set osaCon to current application’s OSAScriptController’s alloc()’s init()
  
set osaView to current application’s OSAScriptView’s alloc()’s initWithFrame:(current application’s NSMakeRect(0, 0, targX, targY))
  
  
set resView to NSTextView’s alloc()’s initWithFrame:(current application’s NSMakeRect(0, 0, targX, targY))
  
resView’s setRichText:true
  
resView’s useAllLigatures:true
  
  
osaCon’s setScriptView:osaView
  
osaCon’s setLanguage:(OSALanguage’s languageForName:"AppleScript")
  
osaCon’s setResultView:resView
  
  
osaView’s setString:theSource
  
osaCon’s compileScript:(missing value) –Compile(構文確認)
  
osaCon’s runScript:(missing value)
  
  
set asRes to resView’s |string|() as list of string or string –as anything
  
  
set aRes to (osaView’s |string|()) as string
  
  
copy asRes to theResult
end execASandReturnString:

on compileASandReturnString:(theSource as string)
  set targX to 1024 –View Width
  
set targY to 2048 –View Height
  
  
set osaCon to current application’s OSAScriptController’s alloc()’s init()
  
set osaView to current application’s OSAScriptView’s alloc()’s initWithFrame:(current application’s NSMakeRect(0, 0, targX, targY))
  
  
set resView to NSTextView’s alloc()’s initWithFrame:(current application’s NSMakeRect(0, 0, targX, targY))
  
resView’s setRichText:true
  
resView’s useAllLigatures:true
  
  
osaCon’s setScriptView:osaView
  
osaCon’s setLanguage:(OSALanguage’s languageForName:"AppleScript")
  
osaCon’s setResultView:resView
  
  
osaView’s setString:theSource
  
osaCon’s compileScript:(missing value) –Compile(構文確認)
  
  
set aRes to (osaView’s |string|()) as string
  
  
return aRes
end compileASandReturnString:

★Click Here to Open This Script 

Posted in OSA | Tagged 10.11savvy 10.12savvy 10.13savvy mi | Leave a comment

miの最前面のドキュメントをAppleScriptとみなして構文確認して戻す

Posted on 4月 24, 2018 by Takaaki Naganoya

テキストエディタ「mi」の最前面のドキュメントをAppleScriptとみなして構文確認してmiの本文に戻すAppleScriptです。

ながらくバージョン3.0のβ版が公開されていたものの、正式版が登場しなかったテキストエディタ「mi」。その正式版が2018.4.21に唐突に登場しました。

そこで、正式版のmiをAppleScriptからコントロールしていろいろ試してみました。

miのAppleScript対応機能は必要なものは十分にそろっているレベルで、最前面のドキュメントの選択部分を取得したり、選択部分に演算結果を戻してみたりと、期待されるような処理は行えます。

そこで、ひととおりの機能を確認してみると、書類の「モード」(種別ごとの書式情報切り替え)をAppleScriptから確認できたりと、他のエディタでは見られないような実装もあります。

ただ、どのテキストエディタでもそうなのですが、書式情報だけ切り替えて認識できてもほとんど実用性はなく、テキストエディタ上でAppleScriptを書く意味はほとんどありません。「構文確認」が行えないので、構文チェックや短縮表記の展開などが一切行えないためです。


▲mi上でモードを「AppleScript」に指定して編集


▲構文確認した結果をmi上に書き戻したところ。「app」–>「application」、「end」–>「end tell」などの短縮表記を展開している

–> Demo Movie

そこで、AppleScript自体でAppleScriptのテキストを構文確認して文法チェックや短縮表現の展開などを行い、結果をテキストエディタ(ここではmi)に書き戻すようにしてみました。

このぐらいの処理なら、アプリケーションに依存している部分はほどんとないので、CotEditorでもJeditΩでも、BBEditでも問題なく行えます。

AppleScript名:miの最前面のドキュメントをAppleScriptとみなして構文確認して戻す
— Created 2018-04-24 by Takaaki Naganoya
— 2018 Piyomaru Software
use AppleScript version "2.5"
use scripting additions
use framework "Foundation"
use framework "OSAKit"

property OSAScript : a reference to current application’s OSAScript
property OSALanguage : a reference to current application’s OSALanguage
property OSALanguageInstance : a reference to current application’s OSALanguageInstance

set targX to 1024 –View Width
set targY to 2048 –View Height

tell application "mi"
  tell front document
    if mode is not equal to "AppleScript" then return
    
set theSource to content
  end tell
end tell

–Compile AppleScript Source
set osaCon to current application’s OSAScriptController’s alloc()’s init()
set osaView to current application’s OSAScriptView’s alloc()’s initWithFrame:(current application’s NSMakeRect(0, 0, targX, targY))
osaCon’s setScriptView:osaView
osaCon’s setLanguage:(OSALanguage’s languageForName:"AppleScript")
osaView’s setString:theSource
osaCon’s compileScript:(missing value) –Compile(構文確認)

set aRes to (osaView’s |string|()) as string

tell application "mi"
  tell front document
    set content to aRes
  end tell
end tell

★Click Here to Open This Script 

Posted in OSA | Tagged 10.11savvy 10.12savvy 10.13savvy mi | Leave a comment

AS構文色分け情報の重複チェック

Posted on 4月 23, 2018 by Takaaki Naganoya

plistから読み取ったAppleScriptの構文色分け書式データをもとに、各構文要素の指定色に重複がないかどうかチェックするAppleScriptです。

もう少しシンプルに書けそうな気もするのですが、、、

AppleScript名:AS構文色分け情報の重複チェック
— Created 2018-04-22 by Takaaki Naganoya
— 2018 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

set aList to {{redValue:145, greenValue:40, blueValue:144, fontName:"Osaka", fontSize:13.0}, {redValue:61, greenValue:12, blueValue:62, fontName:"Osaka", fontSize:13.0}, {redValue:14, greenValue:62, blueValue:251, fontName:"Osaka", fontSize:13.0}, {redValue:120, greenValue:52, blueValue:203, fontName:"Osaka", fontSize:13.0}, {redValue:255, greenValue:0, blueValue:0, fontName:"Osaka", fontSize:13.0}, {redValue:0, greenValue:0, blueValue:0, fontName:"Osaka", fontSize:13.0}, {redValue:145, greenValue:82, blueValue:17, fontName:"Osaka", fontSize:13.0}, {redValue:0, greenValue:0, blueValue:0, fontName:"Osaka", fontSize:13.0}, {redValue:39, greenValue:201, blueValue:201, fontName:"Osaka", fontSize:13.0}, {redValue:15, greenValue:62, blueValue:251, fontName:"Osaka", fontSize:13.0}, {redValue:31, greenValue:182, blueValue:252, fontName:"Osaka", fontSize:13.0}, {redValue:129, greenValue:58, blueValue:217, fontName:"Osaka", fontSize:13.0}, {redValue:93, greenValue:54, blueValue:146, fontName:"Osaka", fontSize:13.0}, {redValue:185, greenValue:12, blueValue:128, fontName:"Osaka", fontSize:13.0}, {redValue:25, greenValue:184, blueValue:126, fontName:"Osaka", fontSize:13.0}, {redValue:156, greenValue:145, blueValue:5, fontName:"Osaka", fontSize:13.0}, {redValue:79, greenValue:0, blueValue:136, fontName:"Osaka", fontSize:13.0}, {redValue:18, greenValue:138, blueValue:139, fontName:"Osaka", fontSize:13.0}}

set cRes to chkASLexicalFormatColorConfliction(aList) of me
–> false–重複があった

on chkASLexicalFormatColorConfliction(aList)
  set anArray to current application’s NSArray’s arrayWithArray:aList
  
set bList to (anArray’s valueForKeyPath:"redValue.stringValue") as list
  
set cList to (anArray’s valueForKeyPath:"greenValue.stringValue") as list
  
set dList to (anArray’s valueForKeyPath:"blueValue.stringValue") as list
  
  
set colStrList to {}
  
repeat with i from 1 to (length of bList)
    set bItem to contents of item i of bList
    
set cItem to contents of item i of cList
    
set dItem to contents of item i of dList
    
set the end of colStrList to bItem & " " & cItem & " " & dItem
  end repeat
  
  
set aRes to returnDuplicatesOnly(colStrList) of me
  
if aRes is equal to {} then
    return true –重複が存在しなかった場合
  else
    return false –重複があった場合
  end if
end chkASLexicalFormatColorConfliction

on returnDuplicatesOnly(aList as list)
  set aSet to current application’s NSCountedSet’s alloc()’s initWithArray:aList
  
set bList to (aSet’s allObjects()) as list
  
  
set dupList to {}
  
repeat with i in bList
    set aRes to (aSet’s countForObject:i)
    
if aRes > 1 then
      set the end of dupList to (contents of i)
    end if
  end repeat
  
  
return dupList
end returnDuplicatesOnly

★Click Here to Open This Script 

Posted in file list OSA Record | Tagged 10.11savvy 10.12savvy 10.13savvy | 1 Comment

指定パスのAppleScript書類の内容をURL文字列化 v3

Posted on 4月 22, 2018 by Takaaki Naganoya

指定したAppleScript書類の内容を読み取って、URL文字列に変換するAppleScriptです。

Shane Stanleyによる「もうちょっと楽に書けるよ」というツッコミです。記述がシンプルになるのはいいことです。

もともと、オリジナルのScriptは10年以上昔に誰かが(Sal Soghoianあたり?)作ったもので、Cocoaの機能が利用できない時代に書かれたものでした。中途半端にCocoaの機能を利用していたので、そこを置き換えたかたちです。

AppleScript名:指定パスのAppleScript書類の内容をURL文字列化 v3
— Created 2018-03-28 by Takaaki Naganoya
— Modified 2018-04-22 by Shane Stanley
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "OSAKit"
use framework "AppKit"

set asPath to choose file of type {"com.apple.applescript.script", "com.apple.applescript.script-bundle"}

set contText to getContentsOfFile(asPath) of me

set encText to makeEncodedScript(contText) of me
set newLinkText to "applescript://com.apple.scripteditor?action=new&script=" & encText
–> "applescript://com.apple.scripteditor?action=new&script=use%20AppleScript%20version%20%222%2E4%22%0D………"

–指定AppleScriptファイルのソースコードを取得する(実行専用Scriptからは取得できない)
— Original Created 2014-02-23 Shane Stanley
on getContentsOfFile(anAlias as {alias, string})
  set anHFSpath to anAlias as string
  
set aURL to current application’s |NSURL|’s fileURLWithPath:(POSIX path of anHFSpath)
  
set theScript to current application’s OSAScript’s alloc()’s initWithContentsOfURL:aURL |error|:(missing value)
  
return theScript’s source() as text
end getContentsOfFile

on makeEncodedScript(contText)
  set aStr to current application’s NSString’s stringWithString:contText
  
set encodedStr to aStr’s stringByAddingPercentEncodingWithAllowedCharacters:(current application’s NSCharacterSet’s URLQueryAllowedCharacterSet())
  
return encodedStr as text
end makeEncodedScript

★Click Here to Open This Script 

Posted in file OSA | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

指定パスのAppleScript書類の内容をURL文字列化 v2

Posted on 4月 21, 2018 by Takaaki Naganoya

指定したAppleScript書類の内容を読み取って、URL文字列に変換するAppleScriptです。

XML-RPC経由でWordPressにAppleScriptのプログラムをHTML化して掲載する時とか、PDFに対して「applescript://」カスタムプロトコルリンクを付加する処理を書いたときに使用しました。クリックすると内容がスクリプトエディタに転送されるリンクを作成するためのものです。

AppleScript名:指定パスのAppleScript書類の内容をURL文字列化 v2
— Created 2018-03-28 by Takaaki Naganoya
— 2018 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "OSAKit"
use framework "AppKit"

property quotChar : string id 34

set asPath to choose file of type {"com.apple.applescript.script", "com.apple.applescript.script-bundle"}

set contText to getContentsOfFile(asPath) of me

set encText to makeEncodedScript(contText) of me
set newLinkText to "applescript://com.apple.scripteditor?action=new&script=" & encText
–> "applescript://com.apple.scripteditor?action=new&script=use%20AppleScript%20version%20%222%2E4%22%0D………"

–指定AppleScriptファイルのソースコードを取得する(実行専用Scriptからは取得できない)
— Original Created 2014-02-23 Shane Stanley
on getContentsOfFile(anAlias as {alias, string})
  set anHFSpath to anAlias as string
  
set aURL to current application’s |NSURL|’s fileURLWithPath:(POSIX path of anHFSpath)
  
set theScript to current application’s OSAScript’s alloc()’s initWithContentsOfURL:aURL |error|:(missing value)
  
return theScript’s source() as text
end getContentsOfFile

on makeEncodedScript(contText)
  set delimA to "★☆temp★☆"
  
set delimB to (retURLencodedStrings(delimA) of me) as text
  
  
set aList to every paragraph of contText
  
set aClass to class of aList
  
if aClass = list then
    set aLen to length of aList
  else
    set aLen to 1
  end if
  
  
set aaList to {}
  
  
set delim to AppleScript’s text item delimiters
  
set AppleScript’s text item delimiters to delimA
  
set bList to aList as text
  
set AppleScript’s text item delimiters to delim
  
  
set aaList to (retURLencodedStrings(bList) of me) as text
  
  
set search_string to delimB as text
  
set replacement_string to "%0D" as text
  
set bList to replace_chars(aaList, search_string, replacement_string) of me
  
  
return bList
end makeEncodedScript

on replace_chars(this_text, search_string, replacement_string)
  set AppleScript’s text item delimiters to the search_string
  
set the item_list to every text item of this_text
  
set AppleScript’s text item delimiters to the replacement_string
  
set this_text to the item_list as string
  
set AppleScript’s text item delimiters to ""
  
return this_text
end replace_chars

on retURLencodedStrings(aText)
  set aStr to current application’s NSString’s stringWithString:aText
  
set encodedStr to aStr’s stringByAddingPercentEncodingWithAllowedCharacters:(current application’s NSCharacterSet’s alphanumericCharacterSet())
  
return encodedStr as text
end retURLencodedStrings

★Click Here to Open This Script 

Posted in file OSA | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

指定のAppleScriptのソースを取得してOLD Style ASかASOCかを判定する v2

Posted on 4月 20, 2018 by Takaaki Naganoya
AppleScript名:指定のAppleScriptのソースを取得してOLD Style ASかASOCかを判定する v2
— Created 2017-06-03 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "OSAKit"

set aFile to choose file of type {"com.apple.applescript.script", "com.apple.applescript.script-bundle"}
set aRes to detectScriptIsPureASorASOC(aFile) of me

–指定AppleScriptファイルがOLD Style ASかASOCかを判定して返す
on detectScriptIsPureASorASOC(aFile)
  set sRes to getASsourceFor(aFile) of me
  
set sName to scriptKind of sRes –Name
  
set sText to scriptSource of sRes –Source
  
if sText = "" or sText = missing value then return missing value
  
  
if sName = "AppleScript" then
    if sText contains "use framework \"Foundation\"" then
      return true –ASOC
    else
      return false –Pure AppleScript
    end if
  else
    –JXAなど他のOSA言語の場合
    
return sName
  end if
end detectScriptIsPureASorASOC

–指定AppleScriptファイルのソースコードを取得する(実行専用Scriptからは取得できない)
on getASsourceFor(anAlias as {alias, string})
  set anHFSpath to anAlias as string
  
set aURL to current application’s |NSURL|’s fileURLWithPath:(POSIX path of anHFSpath)
  
set theScript to current application’s OSAScript’s alloc()’s initWithContentsOfURL:aURL |error|:(missing value)
  
set scriptName to theScript’s |language|()’s |name|() as string
  
set theSource to theScript’s source() as text
  
return {scriptKind:scriptName, scriptSource:theSource}
end getASsourceFor

★Click Here to Open This Script 

Posted in OSA | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

AppleScriptの構文色分けカラーフォーマットをplistから読み込む

Posted on 3月 7, 2018 by Takaaki Naganoya

AppleScriptの構文色分けフォーマットをplistから読み込むAppleScriptです。

ただし、本Scriptで取得した色情報はスクリプトエディタ上で設定した内容と若干RGB値が異なるため、色情報をもとに構文要素を判定するような処理に本Scriptをそのまま用いることは推奨しません。

AppleScript名:AppleScriptの構文色分けカラーフォーマットをplistから読み込む
— Created 2013-11-11 by Shane Stanley
— Changed 2014-12-14 by Takaaki Naganoya
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

set cList to getAppleScriptSourceColors() of me
–> {​​​​​{​​​​​​​redValue:37265, ​​​​​​​greenValue:10280, ​​​​​​​blueValue:37008, ​​​​​​​fontName:"Osaka", ​​​​​​​fontSize:13.0​​​​​}, ​​​​​{​​​​​​​redValue:15672, ​​​​​​​greenValue:3071, ​​​​​​​blueValue:15832, ​​​​​​​fontName:"Osaka", ​​​​​​​fontSize:13.0​​​​​}, ​​​​​{​​​​​​​redValue:3598, ​​​​​​​greenValue:15934, ​​​​​​​blueValue:64507, ​​​​​​​fontName:"Osaka", ​​​​​​​fontSize:13.0​​​​​}, ​​​​​{​​​​​​​redValue:30840, ​​​​​​​greenValue:13364, ​​​​​​​blueValue:52171, ​​​​​​​fontName:"Osaka", ​​​​​​​fontSize:13.0​​​​​}, ​​​​​{​​​​​​​redValue:64764, ​​​​​​​greenValue:10794, ​​​​​​​blueValue:7196, ​​​​​​​fontName:"Osaka", ​​​​​​​fontSize:13.0​​​​​}, ​​​​​{​​​​​​​redValue:0, ​​​​​​​greenValue:0, ​​​​​​​blueValue:0, ​​​​​​​fontName:"Osaka", ​​​​​​​fontSize:13.0​​​​​}, ​​​​​{​​​​​​​redValue:37265, ​​​​​​​greenValue:21074, ​​​​​​​blueValue:4369, ​​​​​​​fontName:"Osaka", ​​​​​​​fontSize:13.0​​​​​}, ​​​​​{​​​​​​​redValue:0, ​​​​​​​greenValue:0, ​​​​​​​blueValue:0, ​​​​​​​fontName:"Osaka", ​​​​​​​fontSize:13.0​​​​​}, ​​​​​{​​​​​​​redValue:10023, ​​​​​​​greenValue:51657, ​​​​​​​blueValue:51657, ​​​​​​​fontName:"Osaka", ​​​​​​​fontSize:13.0​​​​​}, ​​​​​{​​​​​​​redValue:3855, ​​​​​​​greenValue:15934, ​​​​​​​blueValue:64507, ​​​​​​​fontName:"Osaka", ​​​​​​​fontSize:13.0​​​​​}, ​​​​​{​​​​​​​redValue:7967, ​​​​​​​greenValue:46774, ​​​​​​​blueValue:64764, ​​​​​​​fontName:"Osaka", ​​​​​​​fontSize:13.0​​​​​}, ​​​​​{​​​​​​​redValue:33153, ​​​​​​​greenValue:14906, ​​​​​​​blueValue:55769, ​​​​​​​fontName:"Osaka", ​​​​​​​fontSize:13.0​​​​​}, ​​​​​{​​​​​​​redValue:23901, ​​​​​​​greenValue:13878, ​​​​​​​blueValue:37522, ​​​​​​​fontName:"Osaka", ​​​​​​​fontSize:13.0​​​​​}, ​​​​​{​​​​​​​redValue:47484, ​​​​​​​greenValue:3164, ​​​​​​​blueValue:32926, ​​​​​​​fontName:"Osaka", ​​​​​​​fontSize:13.0​​​​​}, ​​​​​{​​​​​​​redValue:6491, ​​​​​​​greenValue:47213, ​​​​​​​blueValue:32320, ​​​​​​​fontName:"Osaka", ​​​​​​​fontSize:13.0​​​​​}, ​​​​​{​​​​​​​redValue:40001, ​​​​​​​greenValue:37149, ​​​​​​​blueValue:1331, ​​​​​​​fontName:"Osaka", ​​​​​​​fontSize:13.0​​​​​}, ​​​​​{​​​​​​​redValue:20379, ​​​​​​​greenValue:0, ​​​​​​​blueValue:35059, ​​​​​​​fontName:"Osaka", ​​​​​​​fontSize:13.0​​​​​}, ​​​​​{​​​​​​​redValue:4539, ​​​​​​​greenValue:35536, ​​​​​​​blueValue:35798, ​​​​​​​fontName:"Osaka", ​​​​​​​fontSize:13.0​​​​​}​​​}

–AppleScriptの構文色分けのカラー値をRGBで取得する
on getAppleScriptSourceColors()
  
  
— get the info as a dictionary
  
set thePath to current application’s NSString’s stringWithString:"~/Library/Preferences/com.apple.applescript.plist"
  
set thePath to thePath’s stringByExpandingTildeInPath()
  
set theInfo to current application’s NSDictionary’s dictionaryWithContentsOfFile:thePath
  
  
— extract relevant part and loop through
  
set theArray to (theInfo’s valueForKey:"AppleScriptSourceAttributes") as list
  
  
set colList to {}
  
  
repeat with i from 1 to count of theArray
    set anEntry to item i of theArray
    
log anEntry
    
    
set colorData to NSColor of anEntry
    
set theColor to (current application’s NSUnarchiver’s unarchiveObjectWithData:colorData)
    
    
set {rVal, gVal, bVal} to retColListFromNSColor(theColor, 65535) of me
    
    
set fontData to NSFont of anEntry
    
set theFont to (current application’s NSUnarchiver’s unarchiveObjectWithData:fontData)
    
    
set aFontName to theFont’s displayName() as text
    
set aFontSize to theFont’s pointSize()
    
    
set aColRec to {redValue:rVal, greenValue:gVal, blueValue:bVal, fontName:aFontName, fontSize:aFontSize}
    
    
set the end of colList to aColRec
  end repeat
  
  
return colList
end getAppleScriptSourceColors

–NSColorからRGBの値を取り出す
on retColListFromNSColor(aCol, aMAX as integer)
  set aRed to round ((aCol’s redComponent()) * aMAX) rounding as taught in school
  
set aGreen to round ((aCol’s greenComponent()) * aMAX) rounding as taught in school
  
set aBlue to round ((aCol’s blueComponent()) * aMAX) rounding as taught in school
  
  
if aRed > aMAX then set aRed to aMAX
  
if aGreen > aMAX then set aGreen to aMAX
  
if aBlue > aMAX then set aBlue to aMAX
  
  
return {aRed, aGreen, aBlue}
end retColListFromNSColor

★Click Here to Open This Script 

Posted in Color OSA System | Tagged 10.11savvy 10.12savvy 10.13savvy Script Editor | 3 Comments

指定パスのAppleScript書類がコンパイル済みかどうかチェック

Posted on 3月 7, 2018 by Takaaki Naganoya
AppleScript名:指定パスのAppleScript書類がコンパイル済みかどうかチェック
— Created 2014-12-16 by Takaaki Naganoya
— 2014 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "OSAKit"

property |NSURL| : a reference to current application’s |NSURL|
property OSAScript : a reference to current application’s OSAScript

–指定AppleScriptがコンパイルずみ(中間コードへの翻訳の意)かどうかをしらべる
set a to (choose file of type {"com.apple.applescript.script-bundle", "com.apple.applescript.script", "com.apple.applescript.text"})
set asRes to chkAScompiled(a) as list of string or string
–> true or false

–指定のAppleScriptファイルがコンパイル(構文確認+中間言語化)ずみかどうかを取得する
on chkAScompiled(anAlias as {alias, string})
  set aURL to |NSURL|’s fileURLWithPath:(POSIX path of anAlias)
  
set asO to OSAScript’s alloc()’s initWithContentsOfURL:aURL |error|:(missing value)
  
  
try
    set compF to asO’s isCompiled() as boolean
    
return compF
  on error
    return false
  end try
end chkAScompiled

★Click Here to Open This Script 

Posted in Color OSA System | Tagged 10.11savvy 10.12savvy 10.13savvy Script Editor | Leave a comment

nameを指定してOSA言語のインスタンスを生成する

Posted on 3月 6, 2018 by Takaaki Naganoya

name(名称)を指定してOSA言語のインスタンスを生成するテストを行うAppleScriptです。

このあたりの話は、スクリプトエディタ上では直接取得できますし、コマンドラインからだとosalangコマンドを実行すれば名称一覧を取得できます。Cocoa経由でどの程度の情報が取得できるのか、ちょっと試してながらく放置したままになっていました。

再度、OSAKit系の情報を探してみても……見当たらない(ーー;

以前にAppleEvent Managerのドキュメントをまるごとオフラインにしていた前科があるので、担当に「(オフラインになっていて)見えないんだけど?」と確認したところ………

 「何が見えないんだ? 最初からそんなもんないぞ。これまでにドキュメントを作ったこともない」

と言われる始末。余計悪いわ(ーー;;;

というわけで、Web上にドキュメントが掲載されていないOSAKit系の情報については、Xcode上から、以下のように操作してヘッダーファイルの内容を確認することが必要なようです。

AppleScript名:nameを指定してOSA言語のインスタンスを生成する
— Created 2018-03-05 by Takaaki Naganoya
— 2018 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "OSAKit"

property OSALanguage : a reference to current application’s OSALanguage
property OSALanguageInstance : a reference to current application’s OSALanguageInstance

set anOSALanguageInstance to OSALanguageInstance’s languageInstanceWithLanguage:(OSALanguage’s defaultLanguage())
set aLanguage to anOSALanguageInstance’s |language|()’s |name|() as string
–> "AppleScript"

set bLanguage to OSALanguage’s languageForName:"AppleScript"
set bName to bLanguage’s |name|() as string
–> "AppleScript"

set cLanguage to OSALanguage’s languageForName:"JavaScript"
set cName to cLanguage’s |name|() as string
–> "JavaScript"

set langArray to (OSALanguage’s availableLanguages()’s valueForKeyPath:"name") as list
–> {"AppleScript", "JavaScript"}

★Click Here to Open This Script 

Posted in Color OSA System | Tagged 10.11savvy 10.12savvy 10.13savvy Script Editor | Leave a comment

Script Editorをコントロールして各構文要素の色情報を取得する v5

Posted on 3月 5, 2018 by Takaaki Naganoya

Script Editorをコントロールして、AppleScriptの各構文要素の色情報を取得するAppleScriptです。

AppleScriptの構文要素の色分けを取得するのに、当初はplistファイルから読み込んでいたのですが、途中から(Mac OS X 10.5あたり?)plistファイルのフォーマットがテキスト形式からバイナリ形式に変更になり、AppleScriptから読み込んでも判定できない内容になりました(Cocoaの機能を使うと読み取れるのですが)。

そこで、「プログラム的には意味はないが、対象の構文要素が入っているテキスト」でAppleScriptを新規ドキュメントを作成してコンパイル(構文確認)を実行。新規ドキュメントからリッチテキストとして書式情報を取得し、想定した文字の位置から指定構文要素に対応する色情報を取得します。

plistの保存形式が途中で変更されたのとは別に、書式つきテキスト(attribute runs)の挙動もOSバージョンによって微妙に変わってきました。

同じデータを与えても、書式の区切りが微妙に変わって、書式(色)情報を固定の箇所から読み取っていてはそのようなOSバージョン変更に伴う挙動の微妙な変更に対応し切れませんでした。そのため、文字列をサーチして毎回動的にデータ位置を検出するように書き換えた経緯があります。

本ルーチンは、変数名のリネーム用に作成したので構文要素確認用のダミーテキストは最低限のものだけを含んでいますが、その気になればすべての構文要素の色情報を取得可能です。

これとは別に、Cocoaの機能を用いてplistから構文書式情報を取得するAppleScriptも存在するものの、計算して微妙に色情報が合わないので、9年前に作成した本ルーチンを使い続けています(当時)。

→ さすがに重要なルーチンなので、Cocoa系の機能を使って処理するように書き換えました。いまはCocoa系ルーチンを使っています

AppleScript名:Script Editorをコントロールして各構文要素の色情報を取得する v5
— Created 2009-06-01 by Takaaki Naganoya
— 2009-2018 Piyomaru Software

set scList to getRexicalColorOfScriptEditor() of me
–> {{32053, 4213, 32213}, {15672, 3071, 15831}, {2841, 6963, 64125}, {8259, 42547, 64473}, {0, 0, 0}, {32202, 16452, 3889}}
–色書式データ。先頭から順番に、、、
–新規テキスト, 演算子など, スクリプティング予約語, コマンド名, 値(数値、データ), 変数およびサブルーチン名

–スクリプトエディタの各構文要素の指定色を返す
–v5の変更点:Leopard以降のStyle runsの挙動変化(スペースを分離する/しない)に対応し、動的にサンプル文を走査するようにした
–v4の変更点:構文要素検出時のテンポラリウィンドウ作成時にScript Editorを隠す
–v3の変更点:重複時のエラー検出を追加
on getRexicalColorOfScriptEditor()
  set aRes to setVisibleOfSpecifiedProcess("Script Editor", false) of me
  
  
set rexList to {"+", "set", "application", "Comment", "1", "a"} –文中から検索するテキスト要素
  
set colList to {} –色情報を入れるリスト
  
  
  
tell application "Script Editor"
    
    
set aDoc to make new document
    
tell front document
      set aName to name
      
–end tell
      
      
–tell document aName
      
–未コンパイル時のテキストを取得
      
set contents to "aaaaa"
      
set rexItem1 to (color of attribute runs)
      
set rexItem1 to contents of (item 1 of rexItem1)
      
      
set colList to {rexItem1}
      
      
      
–各種構文要素を含む文字を入れる
      
set contents to "1 + 1
set a to \"abc\"
tell application \"Finder\"
end tell
–Comment
"

      –追加する場合には、テキストを後ろに追加すること
      
      
try
        compile
      on error
        close without saving
        
return false
      end try
      
      
set rex1 to attribute runs
      
set rex2 to color of attribute runs
      
      
repeat with i in rexList
        set j to contents of i
        
set rC to 1
        
repeat with ii in rex1
          set jj to contents of ii
          
set jj to replaceText(jj, " ", "") of me –スペースを削除する
          
if j = jj then
            set the end of colList to contents of item rC of rex2
            
exit repeat –抜けていた
          end if
          
set rC to rC + 1
        end repeat
      end repeat
      
      
close without saving
    end tell
    
  end tell
  
  
–Script Editorの再表示
  
set aRes to setVisibleOfSpecifiedProcess("Script Editor", true) of me
  
  
–要素の重複検出
  
set aRes to detectDuplicationSimple(colList) of me
  
if aRes = false then
    return false
  else
    return colList
  end if
  
end getRexicalColorOfScriptEditor

–リスト中の重複検出
on detectDuplicationSimple(cList)
  copy cList to ccList
  
  
set j to length of ccList
  
  
repeat with i from 2 to j
    set first_item to item 1 of ccList
    
set ccList to rest of ccList
    
if first_item is in ccList then
      return false
    end if
  end repeat
  
  
return true
end detectDuplicationSimple

–指定プロセスの可視/不可視切り替え
on setVisibleOfSpecifiedProcess(aProc, aBoolean)
  tell application "System Events"
    if exists process aProc then
      set visible of process aProc to aBoolean
      
set resF to true
    else
      set resF to false
    end if
  end tell
  
return resF
end setVisibleOfSpecifiedProcess

–任意のデータから特定の文字列を置換
on replaceText(origData, origText, repText)
  set curDelim to AppleScript’s text item delimiters
  
set AppleScript’s text item delimiters to {origText}
  
set origData to text items of origData
  
set AppleScript’s text item delimiters to {repText}
  
set origData to origData as text
  
set AppleScript’s text item delimiters to curDelim
  
return origData
end replaceText

★Click Here to Open This Script 

Posted in Color OSA System | Tagged 10.11savvy 10.12savvy 10.13savvy Script Editor | 1 Comment

指定スクリプト書類の記述OSA言語を取得する v2

Posted on 2月 8, 2018 by Takaaki Naganoya
AppleScript名:指定スクリプト書類の記述OSA言語を取得する v2
— Created 2017-06-04 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "OSAKit"

set anAlias to choose file of type {"com.apple.applescript.script", "com.apple.applescript.script-bundle"}
set sRes to getOSALangKindFromScriptFile(anAlias) of me
–>  {​​​​​osaName:"AppleScript", ​​​​​osaDesc:"AppleScript.", ​​​​​osaVer:"2.5"​​​}
–>  {​​​​​osaName:"JavaScript", ​​​​​osaDesc:"JavaScript", ​​​​​osaVer:"1.1"​​​}

on getOSALangKindFromScriptFile(anAlias)
  set aURL to current application’s |NSURL|’s fileURLWithPath:(POSIX path of anAlias)
  
set theScript to current application’s OSAScript’s alloc()’s initWithContentsOfURL:aURL |error|:(missing value)
  
  
set scriptName to theScript’s |language|()’s |name|() as string
  
set scriptDesc to theScript’s |language|()’s info() as string
  
set scriptVer to theScript’s |language|()’s |version|() as string
  
  
return {osaName:scriptName, osaDesc:scriptDesc, osaVer:scriptVer}
end getOSALangKindFromScriptFile

★Click Here to Open This Script 

Posted in OSA | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

データのClassを求める

Posted on 2月 8, 2018 by Takaaki Naganoya

データのclassを求めるAppleScriptです。

AppleScriptではもともと、

class of 変数

で、変数に入っているデータのclassが求められます。ただ、CocoaのオブジェクトのClassは求められないので、このようなScriptを書いてみた次第です。

AppleScript名:データのClassを求める
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

set theValue to "10"
set aClass to getClassFromData(theValue) of me
–> "text"

set cRes to getClassFromData(current application’s NSArray’s arrayWithArray:{1, 2, 3}) of me
–> "NSArray"

tell application "System Events"
  set a to process "Finder"
end tell
set dClass to getClassFromData(a) of me
–> "application process"

tell application "Safari"
  if running then
    if (count of every document) > 0 then
      set a to front document
      
set eClass to getClassFromData(a) of me
      
–> "document"
    end if
  end if
end tell

on getClassFromData(aData)
  set aRes to (count {aData} each reference)
  
  
if aRes = 0 then
    –Pure AppleScript Object
    
try
      return (class of aData) as string
    on error
      return false
    end try
  else
    –NSObject
    
set nsObjRes to getClassNameStringFromObject(aData) of me
    
if nsObjRes = false then
      –Maybe application Object
      
return (class of aData) as string
    else
      return nsObjRes –NSObject
    end if
  end if
end getClassFromData

on getClassNameStringFromObject(aObject)
  set classList to {"AddressBook", "AVAsset", "AVAssetExportSession", "AVAudioPlayer", "CGPointZero", "CGPostMouseEvent", "CIColor", "CIFilter", "CIImage", "CIVector", "CLLocation", "CLLocationManager", "CWInterface", "EKAlarm", "EKEventStore", "EKStructuredLocation", "FSEvent", "IOBluetoothDevice", "IOBluetoothHostController", "ITLibrary", "JSContext", "MKMapView", "Myriad Helpers", "NSAffineTransform", "NSAlert", "NSAnimationContext", "NSApp", "NSApplication", "NSArray", "NSAttributedString", "NSAutoreleasePool", "NSBezierPath", "NSBitmapImageRep", "NSBox", "NSBundle", "NSButton", "NSByteCountFormatter", "NSCalendar", "NSCharacterSet", "NSClassFromString", "NSColor", "NSColorList", "NSColorSpace", "NSColorWell", "NSComboBox", "NSCompoundPredicate", "NSCountedSet", "NSData", "NSDataDetector", "NSDate", "NSDateComponents", "NSDateFormatter", "NSDateIntervalFormatter", "NSDatePicker", "NSDecimalNumber", "NSDictionary", "NSEnergyFormatter", "NSError", "NSEvent", "NSFileManager", "NSFileSystemFreeSize", "NSFont", "NSFontCollection", "NSFontManager", "NSGraphicsContext", "NSHelpManager", "NSHomeDirectory", "NSHost", "NSImage", "NSImageView", "NSIndexSet", "NSIntersectionRect", "NSInvocationOperation", "NSJSONSerialization", "NSLengthFormatter", "NSLinguisticTagger", "NSLocale", "NSLocaleIdentifier", "NSLog", "NSMakePoint", "NSMakeRange", "NSMakeRect", "NSMapTable", "NSMassFormatter", "NSMatrix", "NSMenuItem", "NSMetadataQuery", "NSMutableArray", "NSMutableAttributedString", "NSMutableCharacterSet", "NSMutableData", "NSMutableDictionary", "NSMutableIndexSet", "NSMutableSet", "NSMutableString", "NSMutableURLRequest", "NSNetServiceBrowser", "NSNotificationCenter", "NSNumber", "NSNumberFormatter", "NSNumberFormatterRoundDown", "NSNumberFormatterRoundUp", "NSOpenPanel", "NSOperationQueue", "NSOrderedSet", "NSPasteboard", "NSPasteboardItem", "NSPipe", "NSPNGFileType", "NSPointInRect", "NSPopUpButton", "NSPredicate", "NSPrinter", "NSPrintInfo", "NSPrintOperation", "NSProcessInfo", "NSPropertyListFormat", "NSPropertyListImmutable", "NSPropertyListSerialization", "NSRange", "NSRect", "NSRegularExpression", "NSRegularExpressionAnchorsMatchLines", "NSRegularExpressionDotMatchesLineSeparators", "NSRegularExpressionSearch", "NSRunningApplication", "NSSavePanel", "NSScanner", "NSScreen", "NSScriptCommand", "NSSegmentedControl", "NSSet", "NSShadow", "NSSharingService", "NSSlider", "NSSortDescriptor", "NSSound", "NSSpeechRecognizer", "NSSpeechSynthesizer", "NSSpellChecker", "NSSplitView", "NSStatusBar", "NSString", "NSTableColumn", "NSTableView", "NSTask", "NSTextField", "NSTextView", "NSThread", "NSTimeInterval", "NSTimer", "NSTimeZone", "NSUnarchiver", "NSUnionRect", "NSURL", "NSURLComponents", "NSURLConnection", "NSURLDownload", "NSURLQueryItem", "NSURLRequest", "NSURLRequestReloadIgnoringLocalCacheData", "NSUserDefaults", "NSUTF8StringEncoding", "NSUUID", "NSView", "NSWeekCalendarUnit", "NSWindow", "NSWindowController", "NSWorkspace", "NSXMLParser", "NSZeroRect", "NSZeroSize", "ODNode", "ODQuery", "ODSession", "OSAScript", "OSAScriptController", "OSAScriptView", "PDFAnnotation", "PDFDestination", "PDFDocument", "PDFOutline", "PDFPage", "PDFThumbnailView", "PDFView", "QCView", "SBApplication", "WebView", "WKWebView"}
  
  
repeat with i in classList
    set j to contents of i
    
set aClass to current application’s NSClassFromString(j)
    
try
      set aRes to (aObject’s isKindOfClass:aClass) as boolean
    on error
      –May be an Application Object
      
return false
    end try
    
    
if aRes = true then return j
  end repeat
  
  
return false
end getClassNameStringFromObject

★Click Here to Open This Script 

Posted in OSA | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

Post navigation

  • Newer posts

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

Google Search

Popular posts

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

Tags

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

カテゴリー

  • 2D Bin Packing
  • 3D
  • AirDrop
  • AirPlay
  • Animation
  • AppleScript Application on Xcode
  • Beginner
  • Benchmark
  • beta
  • Bluetooth
  • Books
  • boolean
  • bounds
  • Bug
  • Calendar
  • call by reference
  • check sum
  • Clipboard
  • Cocoa-AppleScript Applet
  • Code Sign
  • Color
  • Custom Class
  • 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年2月
  • 2025年1月
  • 2024年12月
  • 2024年11月
  • 2024年10月
  • 2024年9月
  • 2024年8月
  • 2024年7月
  • 2024年6月
  • 2024年5月
  • 2024年4月
  • 2024年3月
  • 2024年2月
  • 2024年1月
  • 2023年12月
  • 2023年11月
  • 2023年10月
  • 2023年9月
  • 2023年8月
  • 2023年7月
  • 2023年6月
  • 2023年5月
  • 2023年4月
  • 2023年3月
  • 2023年2月
  • 2023年1月
  • 2022年12月
  • 2022年11月
  • 2022年10月
  • 2022年9月
  • 2022年8月
  • 2022年7月
  • 2022年6月
  • 2022年5月
  • 2022年4月
  • 2022年3月
  • 2022年2月
  • 2022年1月
  • 2021年12月
  • 2021年11月
  • 2021年10月
  • 2021年9月
  • 2021年8月
  • 2021年7月
  • 2021年6月
  • 2021年5月
  • 2021年4月
  • 2021年3月
  • 2021年2月
  • 2021年1月
  • 2020年12月
  • 2020年11月
  • 2020年10月
  • 2020年9月
  • 2020年8月
  • 2020年7月
  • 2020年6月
  • 2020年5月
  • 2020年4月
  • 2020年3月
  • 2020年2月
  • 2020年1月
  • 2019年12月
  • 2019年11月
  • 2019年10月
  • 2019年9月
  • 2019年8月
  • 2019年7月
  • 2019年6月
  • 2019年5月
  • 2019年4月
  • 2019年3月
  • 2019年2月
  • 2019年1月
  • 2018年12月
  • 2018年11月
  • 2018年10月
  • 2018年9月
  • 2018年8月
  • 2018年7月
  • 2018年6月
  • 2018年5月
  • 2018年4月
  • 2018年3月
  • 2018年2月

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

メタ情報

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

Forum Posts

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

メタ情報

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