1

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/finder@2x.jpg")

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.

ThatCrazyCow
  • 469
  • 2
  • 5
  • 17

1 Answers1

1

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:finder@2x.jpg") 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

ShooTerKo
  • 2,242
  • 1
  • 13
  • 18
  • That has helped but I still get the error: "Finder got an error: Handler can’t handle objects of this class." This error highlights `move source to destination with replacing` which leads me to think that there is something wrong with my method of moving. – ThatCrazyCow Mar 17 '15 at 13:17
  • 1
    I belive you need to add `file` in front of `"source"` – McUsr Mar 17 '15 at 14:49
  • Good point! You can define all paths as aliases also. I updated my answer! – ShooTerKo Mar 17 '15 at 15:10
  • Now it's telling me `File Macintosh HD:Users:[my username]:Desktop:App.app:Contents:Resources:finder.jpg wasn’t found.` – ThatCrazyCow Mar 17 '15 at 16:22
  • Using Skript Editor open the bundle slider and look if the file is there. If not, drag it to that location. – ShooTerKo Mar 17 '15 at 16:29
  • After saving an App it is available in the upper right corner in script Editor. You have access to your bundle content there! – ShooTerKo Mar 17 '15 at 17:14
  • It's there under resources – ThatCrazyCow Mar 17 '15 at 17:41
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/73196/discussion-between-thatcrazycow-and-shooterko). – ThatCrazyCow Mar 17 '15 at 18:36