AppleScript Question

Discussion in 'Mac Programming' started by Wallace25, Mar 23, 2007.

  1. macrumors member

    Wallace25

    Joined:
    Feb 21, 2007
    #1
    I have an applescript that I can't get to work. I am openening a file with a name of "TestScript", then adding text to it. That part works fine, but then I try to have script editor save it, and it saves as untitled.

    Any ideas?

    Here is the script

    set fileLocation to choose folder
    set x to "testText"

    tell application "Script Editor"

    set newDoc to make new document with properties {name:"TestScript"}


    set text of newDoc to x
    compile newDoc
    save newDoc in fileLocation
     
  2. Administrator emeritus

    xUKHCx

    Joined:
    Jan 15, 2006
    Location:
    The Kop
    #2
    bit of a nasty way of doing it, but this seems to work.

    Sure there is probably a better way of doing it.


    set fileLocation to choose folder
    set x to "testText"
    set y to "TestScript"
    tell application "Script Editor"

    set newDoc to make new document with properties {name:y}


    set text of newDoc to x
    compile newDoc
    save newDoc in fileLocation
    tell application "Finder"
    set sav to fileLocation & "Untitled.scpt" as string as alias
    set name of sav to y & ".scpt" as string
    end tell
    end tell
     
  3. macrumors 6502a

    lancestraz

    Joined:
    Nov 27, 2005
    Location:
    RI
    #3
    Use this.
    Code:
    set fileLocation to (((choose folder) as string) & "testScript")
    set x to "testText"
    
    tell application "Script Editor"
    	set newDoc to make new document with properties {name:"TestScript"}
    	set text of newDoc to x
    	compile newDoc
    	save newDoc in fileLocation
    end tell
    You can change the text "testScript" in the first line to whatever you want to save it as.
     
  4. thread starter macrumors member

    Wallace25

    Joined:
    Feb 21, 2007
    #4

    Thanks works great.
     

Share This Page