|
それでは、スクリプトのコードを見てみましょう。
1. スクリプトの最初の行には、スクリプトについての簡単なコメントが記述されます。一行のコメントは、以下のように2つのハイフンで始められます。コメントには、日本語も使用可能です。
-- このスクリプトはファイルを任意のCanvas
8でサポートされているファイル形式に変換して保存します。
ヒント:
複数行にわたるコメントの場合は、(* で開始し、*)で閉じます。
2. 以下のコマンドは、「Finder」を起動し、イメージのソースフォルダと保存用フォルダを指定させ、ソースフォルダ内に存在するファイルの数をカウントするように指示します。
tell application "Finder"
activate
set importFolder to choose folder with prompt "イメージが保存されているフォルダを選択してください。"
set exportFolder to choose folder with
prompt "保存用フォルダを選択してください。"
set nFiles to count folder importFolder each file
3. 変換したいファイル形式を選択するためのダイアログを表示するように指示します。
display dialog "どの形式に変換するか番号で指定してください。"
& return & return & "1=AI, 2=bmp, 3=cals, 4=Canvas,
5=CGM, 6=DCX, 7=DRW, 8=DXF, 9=EPSF, 10=Flash, 11=GIF, 12=HTML, 13=Icon,
14=IFF, 15=jpeg, 16= PCX, 17=PDF, 18=Photoshop, 19=Targa, 20=Tiff, 21=WPG"
default answer ""
set userValue to (text returned of result) as real
end tell
ヒント:
どのコマンドを使ってどのようにCanvasを制御するかについては、Canvasのプログラム ディクショナリを参照することができます。このディクショナリには、AppleScriptで制御可能なCanvas機能がすべてリストされています。このプログラムディクショナリは、Canvasのスペルチェックによって使用されるものではありません。もし、自分でCanvas用のスクリプトを作成してみようという方には、Canvasのプログラム
ディクショナリを閲覧、参照されることをお勧めします。プログラム ディクショナリの開き方はここから!
4. オリジナルのイメージが保存されているフォルダから一つずつファイルを開いて、指定されたファイル形式で保存用フォルダに保存するように指示します。
repeat with i from 1
to nFiles
tell application "Finder"
set f to file i of importFolder
set fName to get name of f
end tell
tell application "Canvas 8"
activate
open (importFolder as string) & fName
if userValue is 1 then
save document 1 in (exportFolder as string) & fName & ".AI"
as AI
else if userValue is 2 then
save document 1 in (exportFolder as string) & fName & ".BMP"
as BMP
else if userValue is 3 then
save document 1 in (exportFolder as string) & fName & ".CAL"
as CALS
else if userValue is 4 then
save document 1 in (exportFolder as string) & fName & ".CNV"
as Canvas
else if userValue is 5 then
save document 1 in (exportFolder as string) & fName & ".CGM"
as CGM
else if userValue is 6 then
save document 1 in (exportFolder as string) & fName & ".DCX"
as DCX
else if userValue is 7 then
save document 1 in (exportFolder as string) & fName & ".DRWI"
as DRW
else if userValue is 8 then
save document 1 in (exportFolder as string) & fName & ".DXF"
as DXF
else if userValue is 9 then
save document 1 in (exportFolder as string) & fName & ".EPS"
as EPSF with options {preview color mode:rgb mode}
else if userValue is 10 then
save document 1 in (exportFolder as string) & fName & ".SWF"
as FLASH
else if userValue is 11 then
save document 1 in (exportFolder as string) & fName & ".GIF"
as GIF
else if userValue is 12 then
save document 1 in (exportFolder as string) & fName & ".HTML"
as HTML
else if userValue is 13 then
save document 1 in (exportFolder as string) & fName & ".ICO"
as ICON
else if userValue is 14 then
save document 1 in (exportFolder as string) & fName & ".IFF"
as IFF
else if userValue is 15 then
save document 1 in (exportFolder as string) & fName & ".JPG"
as JPEG
else if userValue is 16 then
save document 1 in (exportFolder as string) & fName & ".PCX"
as PCX
else if userValue is 17 then
save document 1 in (exportFolder as string) & fName & ".PDF"
as PDF
else if userValue is 18 then
save document 1 in (exportFolder as string) & fName & ".PSD"
as Photoshop
else if userValue is 19 then
save document 1 in (exportFolder as string) & fName & ".TGA"
as TARGA
else if userValue is 20 then
save document 1 in (exportFolder as string) & fName & ".TIF"
as TIFF
else if userValue is 21 then
save document 1 in (exportFolder as string) & fName & ".WPG"
as WPG
end if
close document 1
end tell
end repeat
5. すべてのファイルを変換し終わったら、Canvasを終了するように指示します。
tell application "Canvas
8"
quit
end tell

スクリプトを実行する
実際にこのスクリプトを実行してみましょう!
開かれているスクリプトを実行するには、「Script Editor」ダイアログの左上にある「実行」ボタンをクリックします(右図参照)。実行ボタンがクリックされると、矢印がグレーから明るい緑色に変わります。
|