Arrrrrgh. As a programmer I’m finding Applescripting very frustrating. Here is what I’m trying to do: I want to create a droplet to process text files and save them as Pages documents. As part of the process I want to change the text font and text size and then change the left and right margins. So far I can get Pages to open up the document I drop on the droplet but I can’t manipulate anything. HELP. Below is what I have done so far.
on open these_items
repeat with i from 1 to item i of these_items
set this_item to item i of these_items
tell application "Pages" to open this_item
end repeat
end open
From what I have read here and other places. I need to create a reference and when I try something like
set these_text to this_item
the result is that “These_text” is an alias (Which is what I expected since this_item is an alias. ) I can’t do anything with the alias. What am I doing wrong?
AppleScript is not more or less logical than other programming languages.
An alias is a file reference. Opening a file reference in Pages.app creates a document reference of Pages
on open these_items
repeat with i from 1 to count these_items
set this_item to item i of these_items
tell application "Pages"
set frontDocument to open this_item
tell frontDocument
-- do something
end tell
end tell
end repeat
end open
I recommend to comment out the open handler lines and define these_items as a list of aliases.
Then you get error messages if something goes wrong.
Ok, I changed my script per your suggestion but I’m still having problems. my first thought was this.
set frontdocument to open this_item
tell frontdocument
set left margin of frontdocument to .5
set right margin of frontdocument to .5
end tell
This is what I was planning on replacing your ‘Do something’ comment in the code’. Obviously I’m missing something fundamental. Now that I have a document reference “frontdocument”? How do I access it? I feel like a complete noobie.
on open these_items
repeat with i from 1 to count these_items
set this_item to item i of these_items
tell application "Pages"
set frontDocument to open this_item
tell frontDocument
set left margin to 0.5
set right margin to 0.5
end tell
end tell
end repeat
end open
I checked your code against mine and the only thing different is the “frontDocument” is like this on my machine “frontdocument” and like this on your posts. “frontDocument”.