I want to be able to run a shell script from one of my AppleScripts to change the permissions on a file without the appearance of the annoying authentication dialog, and I want both the password and the file path to be variables.
Assume that my password is “myPassWord” and that the file path is “~/Library/Preferences/gzorch.rtf”
This script works when I run it from the terminal:
chmod 777 ~/Library/Preferences/gzorch.rtf
However, when I run it from an AppleScript, as:
do shell script “chmod 777 ~/Library/Preferences/gzorch.rtf” password “myPassWord” with administrator privileges
I get a message that the file does not exist.
I realize the problem with the difference between AppleScript, which requires a colon instead of a slash for a directory delimiter–but I’ve tried everything I can think of, including writing out the entire path of the file, with no luck.
What I’d like to be able to do is to define the password and file path as variables, as in something like:
tell application “Finder”
set correctPassWord to “myPassWord” as string
set pathToFile to (path to preferences folder) & “gzorch.rtf” as string
set newPathToFile to “” as text
set pathToFileLength to length of pathToFile as integer
repeat with i from 1 to pathToFileLength
set newCharacter to character i of pathToFile
if character i of pathToFile is “:” then
set newCharacter to “/” as string
end if
set newPathToFile to newPathToFile & newCharacter as string
end repeat
set scriptCommand to ““chmod 777 " & newPathToFile & “”” & " password “” & correctPassWord & “” with administrator privileges” as string
do shell script scriptCommand
end tell
I realize that I’m obviously doing something very wrong here, and that it’s probably because I’m overlooking something very simple (it usually does turn out that way), but I’ll be damned if I can figure out just what it is.
Any suggestions?
:?: