フォルダ内のファイル・フォルダ一覧を作成する
=== ↑ 書籍の JavaScript を AppleScript に翻訳しています ===
書籍 2-8 ファイル/フォルダ : 01 選択したフォルダ内のファイル/フォルダ一覧を作成する
書籍ではInDesignのJavaScriptでフォルダ選択のダイアログを表示し、フォルダ内の情報にアクセスしていますが、AppleScriptは、言語自体にダイアログ表示機能があります。
また、フォルダやファイルのリストを取得するには、"Finder.app"に命令しMacのファイルシステムにアクセスします。
それに加えて、MacOSのベースはBSD系のUNIXなので、シェルにコマンドを発行し、結果を得ることも可能です。
フォルダ選択ダイアログを表示するAppleScriptは
choose folder
です。ダイアログに何らかのメッセージを加える場合には、
choose folder with prompt "フォルダを選択してくだサイ"
と、プロンプトオプションを追加します。 選択したフォルダの情報は
result
に alias のクラスが入ってるので、それを取得するか、
set myFolder to choose folder with prompt "もういちど、フォルダを選択してくだサイね"
と変数で受ける方法もあります。
上で set した myFolder を Finder.app に渡すと、フォルダ内のアイテムが取得できます。
tell application "Finder" set myList to every item of myFolder end tell
と変数で受ける方法もあります。
上で set した myFolder を Finder.app に渡すと、フォルダ内のアイテムが取得できます。 myList には Finderの参照形式が入っています。これを文字列として取り出すには、もう一仕事必要です。 Finder参照形式 -> alias クラスへ変換 -> 文字列へ変換
set res to {} repeat with myItem in myList set end of res to ((myItem as alias) as string) end repeat res
変数 res には「文字列」のファイル・フォルダリストが入っています。 それぞれの文字列は ... as alias で alias オブジェクトに変換すると、AppleScriptが理解できる形式になります。
次回は、指定されたフォルダ内の全てのアイテム(サブフォルダの中を含む)を取得します。
OSのバージョン * MacOS Catarina 10.15.5
▼サンプルファイル www.dropbox.com
画像のカラースペースを調べる
=== ↑ 書籍の JavaScript を AppleScript に翻訳しています ===
書籍 2-7 画像:02 RGB画像があるか調べる
画像のカラースペースは image クラスの space プロパティが保持しています。
用語辞書で color プロパティは
space (text, r/o) : The color space.
r/o = リードオンリーとなっていますので、変更はできません。
tell application "Adobe InDesign CC 2019" tell active document activate set the selection to {} repeat with myObj in page items set the selection to myObj if class of myObj is rectangle then set mySpace to imageColorSpace(myObj) of me display dialog mySpace -- > RGB, CMYK, Lab, グレースケール end if end repeat end tell end tell -- 画像のカラースペースを返す on imageColorSpace(myObj) tell application "Adobe InDesign CC 2019" -- class image のリストが帰ってくる set myImages to all graphics of myObj --properties of aImage -- class image のすべてのプロパティ set aImage to item 1 of myImages space of aImage -- 戻り値 = 画像のカラースペース end tell end imageColorSpace
MacOS Catarina 10.15.5 Adobe InDesign CC 2019
▼サンプルファイル
ブログ再開のお知らせ
最終更新から5年も経ってしまいました。
その間いろいろありましたが、現在は以前のようにスクリプトを書く毎日を送っています。
Mac OS や Adobe製品のバージョンも変わりました。 次回の記事から、Script の動作環境が
- Mac OS 10.15.x Catalina
- adobe InDesign CC 2019
となります。
よろしくお願いします。
Excel のウインドウ枠の固定を AppleScript で設定する
随分と更新が止まっていました。みこまやです。 まあ、誰も見てないのでいいか(笑)
業務でExcel のウインドウ枠の固定を手作業で行っていたのですが、シートが多数の場合、設定ミスが目立つようになってきました。 サンプルをググってみたら、日本語で書かれた記事が見当たらず、辿り着いたのは英語のページ。
ちょこっと自分なりにアレンジしたのが以下のスクリプト。
set rowIndex to 5 --この行までが固定されます tell application "Microsoft Excel" tell window 1 try set freeze panes to false -- 枠固定を外す end try end tell tell active sheet select range ("A" & (rowIndex + 1 as string)) -- セルを選択 end tell tell window 1 set freeze panes to true -- 枠固定を実行 end tell end tell
tell 先が window と sheet に分かれるのがキモですかね。
InDesign 解像度が低い画像があるか調べる AppleScript
2-7 01 解像度が低い画像があるか調べる (P.139)
- 作者: (株)シータス,古籏一浩
- 出版社/メーカー: 技術評論社
- 発売日: 2008/11/25
- メディア: 大型本
- 購入: 5人 クリック: 91回
- この商品を含むブログ (8件) を見る
=== 書籍の JavaScript を AppleScript で書いてみます ===
概要(書籍の方法とは異なります)
- 最低解像度を設定する(ダイアログ経由)
- 指定されたページ(今回はP.1)に配置された画像のリストを取得する
- 各画像に対して繰り返す
- 画像解像度を取得
- 画像解像度が最低解像度より小さければ、選択対象リストに追加
- 繰り返し終了
- 選択選択対象リストが空でなければ、選択対象リストの画像を選択状態にする
- メッセージを表示して、終了
部品作製
- InDesign ドキュメント
- AppleScript ハンドラ
-- 最低解像度を取得(ダイアログ表示) on setPPIMin() display dialog "最低解像度を入れてください" default answer 300 text returned of result end setPPIMin -- 指定されたページの全画像を返す on allGraphics(myPage) tell document 1 of application "Adobe InDesign CS6" all graphics of page myPage end tell end allGraphics -- 画像解像度を返す on getPpi(myImage) tell application "Adobe InDesign CS6" set {eX, eY} to effective ppi of myImage -- 画像の{横,縦}の解像度 set {aX, aY} to actual ppi of myImage -- 元の{横,縦}の解像度 return {{eX, eY}, {aX, aY}} end tell end getPpi -- オブジェクトを選択状態にする on selectPageItems(myList) tell application "Adobe InDesign CS6" select myList end tell end selectPageItems -- 選択状態を空にする on clearSelection() tell application "Adobe InDesign CS6" set selection of document 1 to {} end tell end clearSelection -- メッセージを表示 on showMsg(myPpi, itemCount) if itemCount > 1 then set myMsg to "解像度 " & myPpi & "以下の画像は、" & itemCount & "個ありました。" else set myMsg to "解像度 " & myPpi & " 以下の画像は、ありませんでした。" end if tell application "Adobe InDesign CS6" activate display dialog myMsg giving up after 3 end tell end showMsg on tmp() end tmp `````` ## 部品が揃ったので、実行 on run {} --my setUp() my main() my tearDown() end run on setUp() end setUp on main() set ppiMin to setPPIMin() set myList to allGraphics(1) set myItems to {} -- 選択対象アイテム set loop to number of myList repeat with i from 1 to loop set myImage to item i of myList set {myPpi, orgPpi} to getPpi(myImage) set {pX, pY} to myPpi log "PX: " & pX & "PY: " & pY if (pX < ppiMin) or (pY < ppiMin) then set end of myItems to myImage end if end repeat if myItems is not {} then selectPageItems(myItems) else clearSelection() end if showMsg(ppiMin, number of myItems) end main on tearDown() activate display dialog "Script 終了" giving up after 3 end tearDown
実行結果
- OS X 10.8.5
- Adobe InDesign CS6, version: 8.0.2.413