Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Cilerba

macrumors newbie
Original poster
Apr 11, 2012
1
0
I have this code from an "app" that I'm working on in AppleScript...


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

macrumors 65816
Mar 17, 2012
1,114
99
Belgium
Variable?

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 :

Code:
set thefilefolder2 to path to desktop folder as string

to this :

Code:
set thefilefolder2 to (path to desktop as string)

This will not work either :

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

Code:
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.

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

Code:
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"
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.