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

How do I move a script?

I want to make my script check to see if it is in the correct spot. If it is, do nothing. If it isn't, move to correct spot.


Here is what I have, it doesn't work:


set thePath to POSIX path of (path to me)

if thePath = "~/Library/Launcher.app" then


return "Okay"


else



do shell script "mv " & thePath & " ~/Library/Launcher.app"


end if

Posted on Mar 9, 2018 8:26 PM

Reply
Question marked as Best reply

Posted on Mar 10, 2018 9:15 PM

I don't really understand what you said, sorry. But, Like this?

You have a couple of syntax errors in there, but yes. Note that an application package is essentially a folder that the Finder just looks at differently, so your shell script needs to take that into account. The following script adds a trailing delimiter to the string comparison and quotes the strings for the shell just in case there are special characters such as spaces (you can also escape individual characters):


set source to POSIX path of (path to me)
set destination to POSIX path of (path to home folder) & "Library/"

if source = destination & "Launcher.app/" then
  say "OK"
else
  do shell script "mv " & quoted form of source & space & quoted form of destination
end if
3 replies
Question marked as Best reply

Mar 10, 2018 9:15 PM in response to Dv3v

I don't really understand what you said, sorry. But, Like this?

You have a couple of syntax errors in there, but yes. Note that an application package is essentially a folder that the Finder just looks at differently, so your shell script needs to take that into account. The following script adds a trailing delimiter to the string comparison and quotes the strings for the shell just in case there are special characters such as spaces (you can also escape individual characters):


set source to POSIX path of (path to me)
set destination to POSIX path of (path to home folder) & "Library/"

if source = destination & "Launcher.app/" then
  say "OK"
else
  do shell script "mv " & quoted form of source & space & quoted form of destination
end if

Mar 10, 2018 12:00 AM in response to Dv3v

AppleScript does not use various string shortcuts like the shell does - the path to me statement is returning the full path, and the string in your comparison statement does not expand the tilde shortcut. You will need to use/build a complete path (or a relevant portion) for your comparisons - the POSIX path of (path to home folder) statement will get the path to the user's home folder.

Mar 10, 2018 8:54 AM in response to red_menace

I don't really understand what you said, sorry. But,

Like this?:



set thisPath to POSIX path of (path to me)


set thePath to POSIX path of (path tohome folder)


if thisPath = thePath & "Library/Launcher.app" then


return "Okay"


else



do shell script "mv " & thePath & " ~/Library/Launcher.app"


end if

How do I move a script?

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