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

Question:

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

Reply
Question marked as Solved
Answer:
Answer:

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

Posted on

Page content loaded

Mar 10, 2018 12:00 AM in response to Dv3v 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 12:00 AM

Reply Helpful

Mar 10, 2018 8:54 AM in response to red_menace 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

Mar 10, 2018 8:54 AM

Reply Helpful
Question marked as Solved

Mar 10, 2018 9:15 PM in response to Dv3v 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 9:15 PM

Reply Helpful (1)
User profile for user: Dv3v

Question: How do I move a script?