0

I'm trying to bypass prompting. This is a piece of "my" code:

tell application "Finder"
    set folderA4 to choose folder with prompt "Please select the Folder with A4-booklets"
    set allFiles to every file of folderA4
    set listCount to count every item of allFiles
end tell
tell application "Adobe InDesign CS6"
    repeat with i from 1 to listCount
        set myDocument to make document
        set myPDF to choose file
        ...

Later on I need to place this file in InDesign:

tell myPage
    set myPDFPage to place myPDF    
    set myPDFPage to item 1 of myPDFPag
end tell

But I don't want to choose the file manually but automatically in this manner:

tell application "Adobe InDesign CS6"
    repeat with i from 1 to listCount
        set myDocument to make document
        set myPDF to item i of folderA4

So that all the pdf files of folderA4 get chosen automatically...

This however brings an error saying the alias of item 1 cannot be requested. (number -1728)

What am I doing wrong?

Thanks in advance!

Mauritz
  • 117
  • 12

3 Answers3

0

Try this, it should give you a list of pdf files from the folder:

tell application "Finder"
    set folderA4 to choose folder with prompt "Please select the Folder with A4-booklets"
    set allFiles to every file of folderA4
    set listCount to count every item of allFiles
    set pdfFiles to {}
    repeat with i from 1 to listCount
        tell application "Finder" to set {fType, nExt} to ({file type, name extension} of item i of allFiles)
        if (fType is "PDF ") or (nExt is "pdf") then
            set pdfFiles to pdfFiles & {item i}     
        end if
    end repeat
end tell

This is based on a previous answer by jweaks:

Applescript to (if/then) determine file type and choose correct program to open and print file (within batch sequence)

Community
  • 1
  • 1
Nicolai Kant
  • 1,391
  • 1
  • 9
  • 23
  • The folder only contains pdf files so that doesn't really change the situation I tried it and it didn't work. Thanks for the effort though! – Mauritz Feb 23 '15 at 16:28
0

The answer was:

set myPDF to item 1 of allFiles as alias

That's all!

Mauritz
  • 117
  • 12
  • OK, I am glad you work it out, but when I am trying your code snippets from the original question, they work just fine with no alias errors. I suspect this error comes later in your code where you request an alias. As I mentioned the question was quite unclear and you comment did not help – Nicolai Kant Feb 23 '15 at 17:08
0

This works fine for me if I use it like this:

tell application "Finder"
    repeat with i from 1 to listCount
        set myPDF to item i of folderA4

tell application "Adobe InDesign CS6"
    repeat with i from 1 to listCount
        set myDocument to make document

I think mixing finder and InDesign functions does not work in this case. Try to call Finder inside your loop:

repeat with i from 1 to listCount
  tell application "Adobe InDesign CS6"
    set myDocument to make document
  tell application "Finder"
    set myPDF to item i of folderA4
Nicolai Kant
  • 1,391
  • 1
  • 9
  • 23