Friday, October 22, 2021

#1 2021-10-02 09:52:18 am

One208
Member
Registered: 2021-03-15
Posts: 32

Shell path

Hi
wondering why

Applescript:


-- 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

Applescript:


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

The script

Applescript:


--============================================—
# 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
--============================================—


Filed under: shell, shellPaths

Offline

 

#2 2021-10-02 12:22:36 pm

Mockman
Member
From:: Toronto
Registered: 2020-05-27
Posts: 134

Re: Shell path

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.

Offline

 

#3 2021-10-02 12:27:07 pm

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11750
Website

Re: Shell path

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

Applescript:

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


regards

Stefan

Offline

 

#4 2021-10-02 02:35:02 pm

One208
Member
Registered: 2021-03-15
Posts: 32

Re: Shell path

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 ~
smile smile

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)