hi all,
am new to apple scripting…
the task i want to accomplish is as follows.
i have one sample AppleScript file which has script something like…
tell application “Finder”
activate
open file “pdf:a.pdf” of disk “mydisk”
end tell
i have a text file which have list of names of pdf files line by line as:
a.pdf
b.pdf
c.pdf
i need to take the get the pdf file name from the text file & replace it in the third line of the script - open file “pdf:b.pdf” for all the files.
then i need to save the script with the name of the pdf file… with format as “application”
Can anyone provide me a script that allow me create this batch process of SCRIPT FILE CREATION?
It will be very useful if u provide for otherwise i need to do it manually for around 5000 files…
thank u in advance!!
karthik
jonn8
May 7, 2004, 5:02pm
#3
This code demonstrates three separate methods for creating standalone AppleScript applications:
set desktop_path to (path to desktop ) as string
set spawn_types to {“Script Editor”, “osacompile”, “AppleScript”}
set some_variable to text returned of (display dialog “Enter some text:” default answer “Hello World” buttons {“OK”} default button 1 with icon 1)
set the_script to “display dialog “” & some_variable & “” buttons {“OK”} default button 1 with icon 1 giving up after 10”
repeat with spawn_type in spawn_types
try
if (contents of spawn_type ) = “AppleScript” then
–create an applet (editable) using AppleScript:
store script ¬
(run script ¬
“script my_script” & return & ¬
tab & the_script & return & ¬
“end script” & return ¬
& “return my_script”) ¬
in ((desktop_path & “My Script (AS).app”) as file specification )
[b][color=blue]else[/color][/b] [b][color=blue]if[/color][/b] ([color=blue]contents[/color] [b][color=blue]of[/color][/b] [color=green]spawn_type[/color]) = "osacompile" [b][color=blue]then[/color][/b]
--[i][color=olive]create an applet (run-only) using osacompile from the CLI:[/color][/i]
[color=blue]do shell script[/color] "osacompile -e " & ([color=blue]quoted form[/color] [b][color=blue]of[/color][/b] [color=green]the_script[/color]) ¬
& " -o " & ([color=blue]quoted form[/color] [b][color=blue]of[/color][/b] [color=blue]POSIX path[/color] [b][color=blue]of[/color][/b] ([color=green]desktop_path[/color] & "My Script (CLI).app")) ¬
& " -t " & ([color=blue]quoted form[/color] [b][color=blue]of[/color][/b] "APPL") ¬
& " -c " & ([color=blue]quoted form[/color] [b][color=blue]of[/color][/b] "aplt") ¬
& " -x"
[b][color=blue]else[/color][/b] [b][color=blue]if[/color][/b] ([color=blue]contents[/color] [b][color=blue]of[/color][/b] [color=green]spawn_type[/color]) = "Script Editor" [b][color=blue]then[/color][/b]
--[i][color=olive]create an applet (run-only) using Script Editor (may require Script Editor 2.0+):[/color][/i]
[b][color=blue]tell[/color][/b] [color=blue]application[/color] "Script Editor"
[color=blue]make[/color] [color=blue]new[/color] [color=blue]document[/color] [color=blue]at[/color] [b][color=blue]beginning[/color][/b]
[b][color=blue]set[/color][/b] [color=blue]text[/color] [b][color=blue]of[/color][/b] [color=blue]document[/color] 1 [b][color=blue]to[/color][/b] [color=green]the_script[/color]
[color=blue]check syntax[/color] [b][color=blue]of[/color][/b] [color=blue]document[/color] 1
[color=blue]save[/color] [color=blue]document[/color] 1 [color=blue]as[/color] "application" [color=blue]in[/color] (([color=green]desktop_path[/color] & "My Script (SE).app") [b][color=blue]as[/color][/b] [color=blue]file specification[/color]) [b][color=blue]with[/color][/b] [color=blue]run only[/color]
[color=blue]close[/color] [color=blue]document[/color] 1 [color=blue]saving[/color] [color=blue]no[/color]
[b][color=blue]end[/color][/b] [b][color=blue]tell[/color][/b]
[b][color=blue]end[/color][/b] [b][color=blue]if[/color][/b]
[b][color=blue]on[/color][/b] [b][color=blue]error[/color][/b] [color=green]the_error[/color]
[color=blue]activate[/color]
[color=blue]display dialog[/color] [color=green]the_error[/color] [color=blue]buttons[/color] {"OK"} [color=blue]default button[/color] 1 [color=blue]with icon[/color] 0 [color=blue]giving up after[/color] 10
[b][color=blue]end[/color][/b] [b][color=blue]try[/color][/b]
end repeat
activate
display dialog “Spawned!” buttons {“OK”} default button 1 with icon 1 giving up after 10
Jon
[This script was automatically tagged for color coded syntax by Convert Script to Markup Code ]
hi jon,
its working fine for spawn types one & two… but for Script Editor type… the whole script Editor Application itself is quitting abruptly …
is it a problem of my script editor… is any scripting addition is missing?
karthik