Applescript no permission to save .txt file

Discussion in 'Mac Programming' started by Cilerba, Apr 11, 2012.

  1. macrumors newbie

    Joined:
    Apr 11, 2012
    #1
    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:

    How do you think I'd go about fixing this problem?
     
  2. kryten2, Apr 12, 2012
    Last edited: Apr 12, 2012

    macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #2
    Variable?

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

    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"
     

Share This Page