PDA

View Full Version : Applescript no permission to save .txt file




Cilerba
Apr 11, 2012, 07:10 PM
I have this code from an "app" that I'm working on in AppleScript...


tell application "TextEdit"
activate
make new document
set theRAM to "java -Xms" & serverram & "M -Xmx" & serverram & "M -jar ~/Desktop/Bukkit\\ Server/CraftBukkit.jar"
set text of document 1 to theRAM as text
set thefilefolder2 to path to desktop folder as string
set thefilefolder2 to thefilefolder2 & "Bukkit Server:start.command"
save document 1 in thefilefolder2
close document 1 without saving
end tell
do shell script "cd ~/Desktop/Bukkit\\ Server/
chmod +x start.command"


...however, when I run it, I get this:

The document “Untitled” could not be saved as “server.properties”. You don’t have permission.

How do you think I'd go about fixing this problem?



kryten2
Apr 12, 2012, 04:42 PM
When trying to run your code I get the variable serverram is not defined.

You can not use a colon in a Macintosh file or folder name. A colon is used by the Macintosh file system do delimit the path of a file. For example, if you put a file on the desktop named "test", the path name is "Macintosh HD:Desktop Folder:test". This assumes the hard drive is named "Macintosh HD" so the "test" is located in a directory named "Desktop Folder" which is located at the root level of "Macintosh HD"

Remove the colon in "Bukkit Server:start.command"

Change this :

set thefilefolder2 to path to desktop folder as string

to this :

set thefilefolder2 to (path to desktop as string)

This will not work either :

do shell script "cd ~/Desktop/Bukkit\\ Server/
chmod +x start.command"
Change to :

do shell script "cd ~/Desktop/Bukkit\\ Server/;
chmod +x start.command"

This script works but I changed serverram to text like "serverram" for testing .If you try it with "serverram" you will see your file is created with the string inside. It's up to you to modify if serverram really is a variable. Use at your own risk. Scripting TextEdit is not without any danger as I discovered. I erased the contents of my Desktop folder in trying to come up with it. Yours would have done the same if it succeeded.

tell application "TextEdit"
set E to make new document at end of documents
tell E
set theRAM to "java -Xms" & " " & serverram & " " & "M -Xmx" & " " & serverram & " " & "M -jar ~/Desktop/Bukkit\\ Server/CraftBukkit.jar"
set its text to (theRAM as text)
save in file (((path to desktop as Unicode text) & "Bukkit Server:") & "start.command")
close E without saving
quit saving no
end tell
end tell
do shell script "cd ~/Desktop/Bukkit\\ Server/;
chmod +x start.command"

or without using TextEdit :

set theRAM to "java -Xms" & " " & serverram & " " & "M -Xmx" & " " & serverram & " " & "M -jar ~/Desktop/Bukkit\\ Server/CraftBukkit.jar"
do shell script "echo " & theRAM & " >> ~/Desktop/Bukkit\\ Server/start.command"
do shell script "cd ~/Desktop/Bukkit\\ Server/;
chmod +x start.command"