Hello
I have a programming background but am completely new to Applescript. I use Apple’s Pages program from the iWork suite a log. It doesn’t come with any useful Automator actions and my goal is to write some using Applescript. The first script I want to make is to convert a bunch of Appleworks files into Pages documents. To do that I via the OS X GUI I would have to open the appleworks file with Pages and save it with a new filename.
So I’ve written the script below and saved it as an application. It nearly works. The idea is that I can drag a file or folder to the icon and it does the conversion for me.
on open filenames
repeat with f in filenames
tell application "Pages"
open f
close front window saving in my pages_filename(f)
end tell
end repeat
end open
on pages_filename(f)
set this_item to the info for f
set the file_name to the name of this_item
set file_extension to the name extension of this_item
if the file_extension is "" then
set the trimmed_name to the file_name
else
set the trimmed_name to text 1 thru -((length of file_extension) + 2) of the file_name
end if
set target_name to (the trimmed_name & ".pages") as string
return the target_name as string
end pages_filename
-
The first problem I have is with my pages_filename function. It doesn’t return a filename with the full path of the original file e.g. HD:folder:folder:filename.pages.
I don’t know how to get the original path off the filename so I can concatenate it to the new filename. Please could someone tell me how? -
How do you look up what you can do with an object of a particular type for example ˜to the name of’ and ˜to the name extension of’ in the above fragments?
-
There is absolutely no error handling in here at the moment, what should I build in?
-
Am I going about things in the right way to achieve my longer term goal of turning this into an automator action.
Thanks
P