0

I've tried numerous examples online, but all don't seem to work. The image is received via Automator and each file is dispensed incrementally and ran through the following Applescript:

on run {input, parameters}
   set img to item 1 of input

   tell application "Pages"
       set thisDocument to make new document

       tell thisDocument
          make new image with properties {image img}
       end tell

   end tell
end run

It should insert every image into the same Pages document, but instead I'm getting 'Can't make image {image (alias: "certain path") with document id: "certain id"} into type properties of image'.

Can someone point out what I'm doing wrong?


Automator workflow Automator Workflow

1
  • A few things... The Workflow you're showing is incomplete as Get Folder Contents cannot be the first Action in a normal standard Workflow. So what's before it? I'm not running OS X 10.11 however prior to that, by default, the Dispense Items Incrementally Action does not exist, so I cannot replicate the Workflow as you have it to do testing. Are you running OS X 10.11 and is that Action a default Action? One error I see in the AppleScript code is {image img} needs to be {image data:img}. Did you try using a repeat statement as I mentioned in link of my comment in your deleted question? Jan 17, 2016 at 16:58

1 Answer 1

1

Since I do not have the Dispense Items Incrementally Action what I'm going to present is an alternate way of achieving what I understand your end goal to be, at least in part anyway. The code presented below is not polished or complete in that it simply preforms the insertion of the number of images in the selected folder into the document without regard for placement location in the document. You'll have to modify the code to meet your wants/needs. However, if it's not acceptable to you, I do not expect a down dote as I did go to the trouble of trying to offer a reasonable solution, so simply let me know in a comment that it's not the direction you want to go and I'll delete the Answer.

In Automator, I created a Workflow using Ask for Finder Items, setting the Type: to Folders while not checking Allow Multiple Selections, > Get Folder Contents > Run Apple Script and a Folder in Finder containing two .png images named as shown in the Results of your Get Folder Contents Action (although I used PNG files it will work with JPG or any type graphic images supported in Pages).

I then modified your AppleScript code to include the item mentioned in my comment and a repeat statement along with a counter.

I was then able to insert the two images into a Pages document, which happened lexicographically as that's apparently the default in a scenario such as this. So this seems to negate the need for the Dispense Items Incrementally Action, although not having that Action I'm not able to test the difference between the two Workflows.

AppleScript code:

on run {input, parameters}
    set repeatCount to input count
    set n to 1
    tell application "Pages"
        set thisDocument to make new document
        tell thisDocument
            repeat repeatCount times
                set img to item n of input
                make new image with properties {image data:img}
                set n to n + 1
            end repeat
        end tell
    end tell
end run

As previously mentioned, this just inserts the number of images in the selected folder into the document without regard for placement location in the document and you'll need to determine what code is necessary to achieve proper location placement in the document and because this is looping you'll probably need to increment the location position for each image you insert in the document as well.

Even though it's installed I personally do not use Pages, I use LibreOffice, however having searched the Internet a bit I saw example code that dealt with placement location in the document and I would also open the Script Editor app and then open the Pages Dictionary to see what it exposes so you can determine what you have to work with.

3
  • Thanks for your answer. I would upvote, but I do not have enough rep yet. Dispense items is an action I found online here (peachpit.com/articles/article.aspx?p=1327771&seqNum=2 ), sorry I didn't include that. When using your code I'm getting the following error on the data:img line: 'Expected expression, property or key form, etc. but found “:”.' Any idea what I'm doing wrong?
    – Frank
    Jan 18, 2016 at 9:11
  • BTW I've rebuild the exact workflow as you've mentioned
    – Frank
    Jan 18, 2016 at 9:23
  • @Frank, All I can tell you is that what I posted works as advertised for me under OS X 10.8.5 and Pages '09 version 4.3 (1048). That said, I cannot begin to analyze anything until I see what you have in front of you and what versions of OS X and Pages you're using. Also, did you manually type the code or if copied and pasted, what browser are you using Safari, Firefox or Chrome? If you manually typed the code please upload a screenshot of the workflow and provide a link to i so I can see that there are no mistakes in the code. Jan 18, 2016 at 15:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .