Shell path

Hi
wondering why


-- these do not work

do shell script "defaults export com.manytricks.Moom '~/Dropbox (Personal)/Automation Syncs/Moom/'moom.plist"
or 
do shell script "defaults export com.manytricks.Moom '~/Dropbox (Personal)/Automation Syncs/Moom/moom.plist'"

where as


-- This works
do shell script "defaults export com.manytricks.Moom ~/'Dropbox (Personal)'/'Automation Syncs'/Moom/Moom.plist"

The script


--============================================—
# dCre: 2021-Oct-02 @ 16:10
# URL : https://manytricks.com/osticket/kb/faq.php?id=53 
# dMod: 
# Appl: Backup or restore setting
# Libs: None
# Tags: @Moom @shell @BackUp @Restore
----------------------------------------------------------------
-- Set Up BackUp Folder
set BackUpFolder to "~/Dropbox (Personal)/Automation Syncs/Moom/Moom.plist"

-- Set up ProcedureList
set ProcedureList to {"BackUp", "ReStore"}
set chosenOption to choose from list of ProcedureList with prompt "what you want to do, please select:"
if chosenOption is false then
	error number -128 (* user cancelled *)
else
	set chosenOption to chosenOption's item 1 (* extract choice from list *)
end if
if chosenOption is "BackUp" then -- Has export command
	do shell script "defaults export com.manytricks.Moom" & quoted form of BackUpFolder
else if chosenOption is "ReStore" then -- has import command
	do shell script "defaults import com.manytricks.Moom" & quoted form of BackUpFolder
end if
--============================================—

I have only a murky awareness of shell expansion but I think that your issue is that the ‘~’ shouldn’t be inside the quotes, as they prevent the shell from interpreting it and thus, from expanding to your actual path.

If you move the left-most quote one character to the right, i.e. to between the tilde and the slash, then it should work. At least, it does so for me.

The reason is quite simple: do shell script does not expand the tilde in the path when wrapped in quotes.

a safe independent way is a relative path

set BackUpFolder to POSIX path of (path to home folder) & "Dropbox (Personal)/Automation Syncs/Moom/Moom.plist"

Thank you it works
lesson for me
for Shell in applescript

  1. Needs Posix path to file
  2. Quoted path if space in name/ path
  3. Does not expand ~
    :slight_smile: :slight_smile: