John D
John D

Reputation: 159

Using applescript to select a folder and use as variable

I need to modify my current code to allow for the selection of a a folder. My current code is as follows and works to select a folder without issue:

tell application "Finder"
    set sourceFolder to folder POSIX file "/Users/Username/Desktop/Upload/Temp/HighRes/"
    set theFiles to files of sourceFolder
    set inputPath to "/Users/Username/Desktop/Upload/Temp/"
end tell

I have tried the following, but cannot determine the correct syntax to get to where I was in my original code

tell application "Finder"
    set inputPath to folder POSIX file (choose folder with prompt "Please choose folder to be processed")
    set sourceFolder to folder POSIX file (inputPath & "/HighRes")
    set theFiles to files of sourceFolder
end tell

The above processes but errors out and says that finder got an error and cannot make alias "xyz" into type integer.

Upvotes: 0

Views: 1123

Answers (1)

vadian
vadian

Reputation: 285250

Please forget the POSIX dance. The Finder likes its native and alias specifiers.

tell application "Finder"
    -- inputPath is an alias specifier
    set inputPath to (choose folder with prompt "Please choose folder to be processed")
    -- sourceFolder is built as a Finder item specifier
    set sourceFolder to folder "HighRes" of inputPath
    set theFiles to files of sourceFolder
end tell

Even your first snippet can be written in a simpler way

tell application "Finder"
    set sourceFolder to folder "Upload:Temp:HighRes" of desktop
    set theFiles to files of sourceFolder
    set inputPath to folder "Upload:Temp" of desktop
end tell

Upvotes: 1

Related Questions