ThatCrazyCow
ThatCrazyCow

Reputation: 499

Moving files in Applescript, got error: "Finder got an error: Handler can’t handle objects of this class."

I am trying to move files using Applescript, and I get an error every time I run the app. In the contents of the app, I have the file(s) I want to move (so if I distribute the app the users won't have to separately download the file(s)). That is also why I am using ((path to home folder as text) and adding the specific file path past that. Here is my code:

set source to ((path to home folder as text) & "/Contents/Resources/finder.jpg")
set source2 to ((path to home folder as text) & "/Contents/Resources/[email protected]")

set destination to alias "Macintosh HD:System:Library:CoreServices:Dock.app:Contents:Resources:"

tell application "Finder"
    move source to destination with replacing
    move source2 to destination with replacing
end tell

p.s. I checked just about every related question/answer there is on here, and none helped.

Upvotes: 1

Views: 1994

Answers (1)

ShooTerKo
ShooTerKo

Reputation: 2282

a simple display dialog source would have led you to the solution:

  1. path to home folder returns an alias to your HOME folder (Macintosh HD:Users:your name:). I think you wanted path to me instead which points to your app.
  2. analias as text returns a path string using : as delimiters and you append parts that use / to delimit the path components
  3. analias as text returns a path string that ends with : in case of directories

Summary: Try

set source to ((path to me as text) & "Contents:Resources:finder.jpg")

UPDATE: You can't use alias ..., better use is ... as alias and I think, maybe duplicate is better here...

set source to ((path to me as text) & "Contents:Resources:finder.jpg") as alias
set source2 to ((path to me as text) & "Contents:Resources:[email protected]") as alias

set destination to "Macintosh HD:System:Library:CoreServices:Dock.app:Contents:Resources:" as alias

tell application "Finder"
    duplicate source to destination with replacing
    duplicate source2 to destination with replacing
end tell

Enjoy, Michael / Hamburg

Upvotes: 1

Related Questions