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

タグ: Illustrator

Illustratorで指定のartboardの名称を取得する

Posted on 1月 11, 2019 by Takaaki Naganoya

Adobe Illustratorで指定のartboardの名称を取得するAppleScriptです。

本来であれば、Illustratorのdocument以下のartboardの名称を取得するのであれば、

tell application "Adobe Illustrator"
  set aName to name of artboard 1 of document 1
end tell

★Click Here to Open This Script 

で取得できる「はず」ですが、実際にAdobe Illustratorに対してこれを実行するとエラーになります(Adobe Illustrator CC2018=Adobe Illustrator v22.1にて実行)。

これは、Adobeがいいかげんな実装を行って、出荷前に一切のチェックを行わないためです。100% Adobeのせいです。

ちなみに、このproperty値からnameをIllustratorへのtellブロック外で取得すると、

のようになります。エラーメッセージの文字列としては取得できることがわかります。エラーメッセージのダイアログではAdobe IllustratorのAppleScript用語辞書の予約語を用いて表示が行われていますが、実際にエラーメッセージを(Adobe Illustratorのtellブロック外で)文字列として取得すると、用語辞書が用いられないので生のAppleEventの文字列を相手にすることになります。

というわけで、手段をえらばずにエラーメッセージから名前を取り出してみました。任意のアートボードのプロパティ値を取得してgetArtboardNameFromPropertiesを呼び出すと、アートボード名を抽出します。なお、動作原理の都合上、アートボード名にダブルクォートを含まないようにしてください。

こんなイレギュラーでトリッキーなやり方が必要なのは、Adobeの開発者がバカだからです(本当に)。心の底から軽蔑します(artboardのnameを取得する場合には、部分的にJavaScriptを呼び出して実行してもOK、というかその方法が推奨されます)。

AppleScript名:アートボードの名前を取得する
—
–  Created by: Takaaki Naganoya
–  Created on: 2019/01/11
—
–  Copyright © 2019 Piyomaru Software, All Rights Reserved
—
use AppleScript version "2.4" — Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

tell application "Adobe Illustrator"
  tell document 1
    tell artboard 1
      set aProp to properties
      
set aName to getArtboardNameFromProperties(aProp) of me
    end tell
  end tell
end tell

on getArtboardNameFromProperties(aProp)
  set beginStr to "«class bAl9»:\""
  
  
try
    set aRec to aProp as string
  on error erM
    set offsetA to offset of beginStr in erM
    
set ermB to text (offsetA + (length of beginStr)) thru -1 of erM
    
set offsetB to offset of "\"" in ermB
    
set resB to text 1 thru (offsetB – 1) of ermB
    
return resB
  end try
  
  
error "Illigal Data Format" –Error
end getArtboardNameFromProperties

★Click Here to Open This Script 

Posted in How To Raw AppleEvent Code | Tagged 10.12savvy 10.13savvy Illustrator | 2 Comments

複数のアートボードを持つAI書類を、デスクトップにアートボードごとに分割して保存

Posted on 8月 11, 2018 by Takaaki Naganoya

Adobe Illustrator CC 2018(バージョン22.1)で、複数のアートボードを持つAdobe Illustrator書類をアートボードごとに分割保存するAppleScriptです。

オプションの指定方法にものすごく納得しづらいものを感じるものの、これで動くので仕方ないだろうかというところ。

AppleScript名:複数のアートボードを持つAI書類を、デスクトップにアートボードごとに分割して保存.scptd
use AppleScript version "2.4" — Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

set dtPath to ((path to desktop) as string) & "template.ai"

tell application "Adobe Illustrator"
  tell front document
    set aCount to (count every artboard) as string
    
set sOpt to {class:Illustrator save options, save multiple artboards:true, artboard range:"1-" & aCount}
    
save as Illustrator in file dtPath with options sOpt
  end tell
end tell

★Click Here to Open This Script 

Posted in file File path | Tagged 10.11savvy 10.12savvy Illustrator | Leave a comment

オープン中のIllustrator書類をartboardごとに分割 v3

Posted on 8月 9, 2018 by Takaaki Naganoya

Adobe Illustrator CC 2018(バージョン22.1)で、オープン中の(複数のアートボードを持つ)書類を、アートボード単位で別書類に分けるAppleScriptの改修版です。

書類は(とりあえず)デスクトップに書き込まれます。前バージョンのように、アートボード外のオブジェクトが残るといったことはありません。

「exportSelectedArtwork」という長いコマンドを見つけて、ためしてみたら期待どおりの挙動であったために使ってみました。

……すると、なおのことAppleScriptからartworkのselectができないのか?(実行すると100% Illustratorがクラッシュする) artworkからnameの取得ができないのか?(実行するとエラーになる)というあたりが謎です。

artboardも選択状態になっている(はず)だと思って、そのまま実行してみたところ、artboardのサイズでは書き出されていないようです。少し別の方法を試す必要があり、自分は前バージョンのScriptにもどって作業を行っています。

AppleScript名:オープン中のIllustrator書類をartboardごとに分割 v3.scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2018/08/07
–  Modified on: 2018/08/09
–  Copyright © 2018 Piyomaru Software, All Rights Reserved
—
use AppleScript version "2.5" — El Capitan (10.11) or later
use framework "Foundation"
use scripting additions

set dPath to (path to desktop) as string
set namesList to {}

tell application "Adobe Illustrator"
  tell front document
    set aCount to count every artboard
    
set aPath to (file path) as string
  end tell
  
  
repeat with i from 1 to aCount
    set aName to getArtboardName(i – 1) of me –index base correction (1 –> 0)
    
set outPath to dPath & aName & ".ai"
    
    
selectArtboard(i – 1) of me –index base correction (1 –> 0)
    
    
tell front document
      selectobjectsonactiveartboard
      
exportSelectedArtwork to file outPath
    end tell
  end repeat
end tell

–https://lists.apple.com/archives/applescript-users/2015/Jul/msg00104.html
on selectArtboard(theArtboardIndex as string)
  tell application "Adobe Illustrator"
    tell front document
      –Index is 0 based
      
do javascript ("app.activeDocument.artboards.setActiveArtboardIndex(" & theArtboardIndex & ")")
    end tell
  end tell
end selectArtboard

on getArtboardName(theArtboardIndex as string)
  tell application "Adobe Illustrator"
    tell front document
      –Index is 0 based
      
do javascript ("app.activeDocument.artboards[" & theArtboardIndex & "].name")
    end tell
  end tell
end getArtboardName

★Click Here to Open This Script 

Posted in file File path | Tagged 10.12savvy Illustrator | Leave a comment

オープン中のIllustrator書類をartboardごとに分割 v2

Posted on 8月 9, 2018 by Takaaki Naganoya

Adobe Illustrator CC 2018(バージョン22.1)で、オープン中の(複数のアートボードを持つ)書類を、アートボード単位で別書類に分けるAppleScriptです。

書類は(とりあえず)デスクトップに書き込まれます。

こういうコマンドが最初からあってもおかしくないところですが、存在していないようなので書いてみました。まずは、オープン中の書類のパスを取得し、各アートボードの名称を取得して書き出し時のファイル名として使用します。

元ファイルをクローズしては、デスクトップに新規名称でコピーし、コピーした書類をオープン、書き出し対象外のアートボードを順次選択してはアートボード上のオブジェクトを削除してアートボード自体も削除、すべて削除したら保存してクローズという動作を行います。

本来であれば高速化のために複数のアートボードを一括で削除することを考えるところですが、アートボードの削除だけであればできるものの、アートボード上のオブジェクトの削除が行えなくなってしまうので、順次削除に落ち着きました。また、本Scriptが本気でスピードを求められるようなハードな用途ではなく、文字や画像の流し込みテンプレートのメンテナンス用という「平和な用途」のために作成したものであるため、高速化処理については考慮していません。

最初からアートボード外に置かれたオブジェクトについては削除していません。あくまで自分用のツールなので作り込む必要性を感じません。気が向いたら削除するのではないでしょうか。

本Scriptの作成中にも、単にAppleScriptで命令を出しただけで派手にクラッシュしまくるAdobe Illustrator。バージョンが上がって見た目が変わっても、あの出来の悪いIllustratorであることに変わりはないのだと思い知らされました。

AppleScript名:オープン中のIllustrator書類をartboardごとに分割 v2.scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2018/08/07
—
–  Copyright © 2018 Piyomaru Software, All Rights Reserved
—
use AppleScript version "2.5" — El Capitan (10.11) or later
use framework "Foundation"
use scripting additions

set dPath to (path to desktop) as string
set namesList to {}

tell application "Adobe Illustrator"
  tell front document
    set aCount to count every artboard
    
set aPath to (file path) as string
  end tell
  
  
repeat with i from 1 to aCount
    set aName to getArtboardName(i – 1) of me –index base correction (1 –> 0)
    
set the end of namesList to aName
  end repeat
  
  
close every document saving no
end tell

repeat with i from 1 to aCount
  
  
set aRes to retSerialListWithExclusion(1, aCount, i) of me
  
set aaRes to reverse of aRes –artboardをIndex値で指定するため、先頭から削除するとIndex値が変わる。そのため逆順に処理
  
  
set tmpName to contents of item i of namesList
  
  
set fromFile to POSIX path of aPath
  
set fromFilePOSIX to quoted form of POSIX path of fromFile
  
  
set toFile to (dPath & tmpName & ".ai")
  
set toFilePOSIX to quoted form of POSIX path of toFile
  
  
set shText to "cp " & fromFilePOSIX & " " & toFilePOSIX
  
do shell script shText
  
  
tell application "Adobe Illustrator"
    open file toFile
    
tell front document
      repeat with ii in aaRes
        set jj to ii as integer
        
selectArtboard(jj – 1) of me –index base correction (1 –> 0)
        
selectobjectsonactiveartboard
        
delete selection
        
delete artboard jj
      end repeat
      
      
close with saving
    end tell
  end tell
  
end repeat

–https://lists.apple.com/archives/applescript-users/2015/Jul/msg00104.html
on selectArtboard(theArtboardIndex as string)
  tell application "Adobe Illustrator"
    tell front document
      –Index is 0 based
      
do javascript ("app.activeDocument.artboards.setActiveArtboardIndex(" & theArtboardIndex & ")")
    end tell
  end tell
end selectArtboard

on getArtboardName(theArtboardIndex as string)
  tell application "Adobe Illustrator"
    tell front document
      –Index is 0 based
      
do javascript ("app.activeDocument.artboards[" & theArtboardIndex & "].name")
    end tell
  end tell
end getArtboardName

on retSerialListWithExclusion(aFromNum as integer, aToNum as integer, anEXnum as integer)
  set outList to {}
  
repeat with i from aFromNum to aToNum
    if i = anEXnum then
      —
    else
      set the end of outList to i
    end if
  end repeat
  
  
return outList
end retSerialListWithExclusion

★Click Here to Open This Script 

Posted in file File path shell script | Tagged 10.12savvy Illustrator | Leave a comment

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

Google Search

Popular posts

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

Tags

10.11savvy (1101) 10.12savvy (1242) 10.13savvy (1390) 10.14savvy (586) 10.15savvy (434) 11.0savvy (277) 12.0savvy (185) 13.0savvy (55) CotEditor (60) Finder (47) iTunes (19) Keynote (98) NSAlert (60) NSArray (51) NSBezierPath (18) NSBitmapImageRep (20) NSBundle (20) NSButton (34) NSColor (51) NSDictionary (27) NSFileManager (23) NSFont (18) NSImage (41) NSJSONSerialization (21) NSMutableArray (62) NSMutableDictionary (21) NSPredicate (36) NSRunningApplication (56) NSScreen (30) NSScrollView (22) NSString (117) NSURL (97) NSURLRequest (23) NSUTF8StringEncoding (30) NSView (33) NSWorkspace (20) Numbers (56) Pages (37) Safari (41) Script Editor (20) WKUserContentController (21) WKUserScript (20) WKUserScriptInjectionTimeAtDocumentEnd (18) WKWebView (23) WKWebViewConfiguration (22)

カテゴリー

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

アーカイブ

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

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

メタ情報

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

Forum Posts

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

メタ情報

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