Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

File paths and moving files

I'm having trouble with what I thought would be a simple script. All I want to do is create a simple script that moves Pages templates into the appropriate template folder. I keep getting the following error:

"Applescript Error
Finder got an error: Handler can't handle objects of this class"

Here's the script that has the error:

set theFile to choose file
set theFolder to path to application support from user domain
set thePath to theFolder & "iWork:Pages:Templates:My Templates:"
display dialog thePath as string -- displays correct path the the folder I want
tell application "Finder"
move theFile to thePath
end tell

I appreciate any help I can get.

thanks,

G4 Tower, Mac OS X (10.4.11)

Posted on Jun 6, 2008 8:39 AM

Reply
5 replies

Jun 6, 2008 9:17 AM in response to tjrazor

You've run into one of those subtle coercion issues in AppleScript.

The problem lies with the line:

set thePath to theFolder & "iWork:Pages:Templates:My Templates:"


In this case, theFolder is an alias (the result of the path to command) and "iWork:Pages...." is a text object. When you concatenate two different classes (e.g. alias and string) the result is a list:

-->{alias "HD:users:username:Library:Application Support:", "iWork:Pages:Templates:My Templates:"}


Therefore, the move command fails because you're telling the Finder to move a file into a list, which can't be done.

The solution is quite simple - be more expilict about what thePath is. In this case, simple appending "as text" to the line fixes the problem:

set thePath to theFolder & "iWork:Pages:Templates:My Templates:" as text


Now thePath is a single text object which the Finder will coerce to a folder path when used in the move command. If you want to be even more explicit, you could:

move theFile to folder thePath

Jun 6, 2008 9:39 AM in response to Camelot

Thanks so much for your help. I thought I had tried that, but now I see I had "as string" rather than "as text" I rarely work with Applescript and I would have thought those were the same. Anyway, the script now works and I'd like to make one adjustment. I'd like to create a new folder and put the file in that folder. Here's the script, but I'm getting a different error. Hopefully it's just a silly mistake.

set theFile to choose file
set theFolder to path to application support from user domain
set thePath to theFolder & "iWork:Pages:Templates:" as text
display dialog thePath as string
set baseFolder to make new folder at thePath with properties {name:"GS Templates"} -- added this
tell application "Finder"
move theFile to folder baseFolder
end tell

Error I'm getting is:
"AppleScript Error
Can't make current application into type location reference."

I appreciate your time,

Jun 6, 2008 9:50 AM in response to Camelot

I tried the following:

set theFile to choose file
set theFolder to path to application support from user domain
set thePath to theFolder & "iWork:Pages:Templates:" as text
display dialog thePath as string
--set baseFolder to make new folder at thePath with properties {name:"GS Templates"}
tell application "Finder"
make new folder at thePath with properties {name:"GS Templates"}
end tell
set finalFolder to thePath & "GS Templates:" as text
tell application "Finder"
move theFile to folder finalFolder
end tell

Error:
"AppleScript Error
Finder got an error: Can't make class folder."

Once again, I appreciate your help.

Jun 6, 2008 6:41 PM in response to tjrazor

Enter the code below ...

-- Code starts here --

property tPath : ((path to application support from user domain) as string) & "iWork:Pages:Templates:My Templates:"

on run {} -- Allow user to select multiple files.
my handle_items(choose file with multiple selections allowed)
end run

on open (dItems) -- Allow user to drag multiple files onto applet.
my handle_items(dItems)
end open

on handle_items(localItems)
repeat with i in localItems -- Move selected items.
try
tell application "Finder" to move item i to folder tPath
end try
end repeat
end handle_items

-- Code ends here --

... and save as an application (AppleScript applet).

Now, you can double click on the applet for manual, or drag items onto the applet for automatic, processing.

File paths and moving files

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.