Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Apr 11, 2012, 07:10 PM   #1
Cilerba
macrumors newbie
 
Join Date: Apr 2012
Applescript no permission to save .txt file

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:

Quote:
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?
Cilerba is offline   0 Reply With Quote
Old Apr 12, 2012, 04:42 PM   #2
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: Belgium
Variable?

When trying to run your code I get the variable serverram is not defined.

Quote:
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 by kryten2; Apr 12, 2012 at 07:46 PM.
kryten2 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Applescript - formatting a txt file using write dam316 Mac Applications and Mac App Store 0 May 4, 2014 05:26 PM
AppleScript: How do I save multiple Excel sheets to one pdf using Applescript sbtaylor1 Mac Programming 0 Oct 28, 2013 11:38 PM
in Aperture it states "You don’t have permission to save the file" fitworldmac Digital Photography 2 Mar 3, 2013 08:11 PM
where is the txt file that save's everything i'm typing in mac? giwrgosae Mac Basics and Help 5 Nov 5, 2012 10:27 AM
Resolved: Applescript: List/txt.file question h1068 Mac Programming 5 Jul 3, 2012 06:30 PM

Forum Jump

All times are GMT -5. The time now is 09:45 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC