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

AppleScript bizarre error

do shell script "cd " & selectedPath & "; say -v \"Samantha\" \"" & typeText & "\"" & finalName & " -o \"" & fileName & "\"" with administrator privileges


Here's the weird thing... if I remove "with administrator privileges," the script throws an error message "cd: no such file or directory."


If I remove the variable selectedPath and type out the path manually, it works without admin access. However, selectedPath and the path I typed out are exactly the same (I added a display dialog command which prints out selectedPath to make sure it was formatted correctly).


1) If it were a permissions issue, I would think I would get an error related to permissions. Anyone know why I got that error?

2) Why are admin privileges required just to change the directory, and why is it different for a variable vs. hard-coded text?

 MacBook Air-OTHER, OS X Mavericks (10.9.5), 13 in, Mid 2013, Core i5, 256GB

Posted on Apr 17, 2015 11:37 AM

Reply
Question marked as Best reply

Posted on Apr 17, 2015 8:54 PM

I like to print out what is passed to unix. So, I do:


set unix_input to "cd " & selectedPath & "; say -v \"Samantha\" \"" & typeText & "\"" & finalName & " -o \"" & fileName & "\""

log "unix_input=" & unix_input

do shell script unix_input with administrator privileges




I cannot make much sense of this. It seems you have a cd then a say command. Don't know why this needs admin.


and you do have the problem of funnie characters in the filename. Use "quoted form". Manual quoting may not be enough. Here is the way:


(*


It is easier to diagnose problems with debug information. I suggest adding log statements to your script to see what is going on. Here is an example.



Author: rccharles


For testing, run in the Script Editor.

1) Click on the Event Log tab to see the output from the log statement

2) Click on Run


For running shell commands see:

http://developer.apple.com/mac/library/technotes/tn2002/tn2065.html




*)



on run

-- Write a message into the event log.

log " --- Starting on " & ((current date) as string) & " --- "

-- debug lines

set desktopPath to (path to desktop) as string

log "desktopPath = " & desktopPath


set unixDesktopPath to POSIX path of desktopPath

log "unixDesktopPath = " & unixDesktopPath


set quotedUnixDesktopPath to quoted form of unixDesktopPath

log "quoted form is " & quotedUnixDesktopPath


try

set fromUnix to do shell script "ls -l " & quotedUnixDesktopPath

display dialog "ls -l of " & quotedUnixDesktopPath & return & fromUnix

on error errMsg

log "ls -l error..." & errMsg

end try


end run

21 replies
Question marked as Best reply

Apr 17, 2015 8:54 PM in response to stevejobsfan0123

I like to print out what is passed to unix. So, I do:


set unix_input to "cd " & selectedPath & "; say -v \"Samantha\" \"" & typeText & "\"" & finalName & " -o \"" & fileName & "\""

log "unix_input=" & unix_input

do shell script unix_input with administrator privileges




I cannot make much sense of this. It seems you have a cd then a say command. Don't know why this needs admin.


and you do have the problem of funnie characters in the filename. Use "quoted form". Manual quoting may not be enough. Here is the way:


(*


It is easier to diagnose problems with debug information. I suggest adding log statements to your script to see what is going on. Here is an example.



Author: rccharles


For testing, run in the Script Editor.

1) Click on the Event Log tab to see the output from the log statement

2) Click on Run


For running shell commands see:

http://developer.apple.com/mac/library/technotes/tn2002/tn2065.html




*)



on run

-- Write a message into the event log.

log " --- Starting on " & ((current date) as string) & " --- "

-- debug lines

set desktopPath to (path to desktop) as string

log "desktopPath = " & desktopPath


set unixDesktopPath to POSIX path of desktopPath

log "unixDesktopPath = " & unixDesktopPath


set quotedUnixDesktopPath to quoted form of unixDesktopPath

log "quoted form is " & quotedUnixDesktopPath


try

set fromUnix to do shell script "ls -l " & quotedUnixDesktopPath

display dialog "ls -l of " & quotedUnixDesktopPath & return & fromUnix

on error errMsg

log "ls -l error..." & errMsg

end try


end run

Apr 17, 2015 8:13 PM in response to rccharles

According to the event log, selectedPath's value is ~/Desktop/VR_Ringtones. When I manually type in ~/Desktop/VR_Ringtones instead of passing in the variable, it works without administrator access. I wonder why, since the values are identical. Also, the folder in question is one that the script creates, so it shouldn't be a privileged file.


Thanks for your help so far.

Apr 17, 2015 9:15 PM in response to stevejobsfan0123

The difference is unclear to me, I just thought it could be something in how say operates inside Applescript.

Are you echoing with '-o' ? That is not an option echo supports 🙂


Double check your home folder in case the cd is failing & there is junk being echoed into home (or your admins home).


I get this from a test…

User uploaded file


…

set selectedPath to "~/Desktop"

set fileName to "thefile"

do shell script "cd " & selectedPath & "; echo 'something' > " & fileName

Is there something screwy about the folder you are creating?



(P.S. grab this bookmarklet to fix the lousy negative indent that this forum creates when pasting from Script Editor, it cleans up the form)

http://marklets.com/De-indent.aspx

Apr 17, 2015 9:32 PM in response to Drew Reece

This works for me on 10.9.5

set selectedPath to "~/Desktop"

set fileName to "thefile"

set typeText to "typeText"

set finalName to "finalName"

do shell script "cd " & selectedPath & "; echo 'something' > " & fileName

log "Our variables: " & typeText & " " & finalName & " " & fileName

do shell script "cd " & selectedPath & "; say -v \"Alex\" \"" & typeText & "\"" & finalName & " -o \"" & fileName & "\"" --with administrator privileges



I get a text file with 'something' & an aiff with Alex saying "typeText finalName".

No admin privileges are needed, I don't have Samantha installed, try other voices.

Apr 17, 2015 9:39 PM in response to stevejobsfan0123

How bizarre. Maybe there is a dictionary of known voices that is failing for Applescript alone. I have to wonder if permissions may be at play for the voices or other supporting files.


The /System and /Applications paths will be restricted, so I understand why they would require admin permissions, try /Users/Shared of a 'safe place' to test.


What does Terminal output - any sign of Samantha?

say -v?


https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/ man1/say.1.html

Apr 18, 2015 2:44 PM in response to Drew Reece

~/Desktop/VR_Ringtones

😠 You cannot use ~ as a shortcut to your home folder in a do shell script. I do not understand the reason for this restriction. Also, you should realize that your bash profile is not run in a do shell script.


You need to specify the path to your home folder/directory.


    set homePath to (path to home folder) as string
    log "homePath = " & homepPath

    set unixhomepPath to POSIX path of homePath
    log "unixhomePath = " & unixhomePath


the unix command for finding the current path is:

pwd

the shell will be in the home folder/directory.


Robert

AppleScript bizarre error

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