Note that there are some explanatory texts on larger screens.

plurals
  1. POwriting/reading a single variable in applescript
    primarykey
    data
    text
    <p>I'm just starting with applescript in xcode and currently have an app that asks for a folder location, then creates a folder structure. </p> <pre><code>on buttonClick_(sender) set theLocation to choose folder with prompt "Where to save your project?" tell application "Finder" set newFolder to make new folder at theLocation with properties {name:(theTextField's stringValue() as string)} set fontsFolder to make new folder at newFolder with properties {name:"fonts"} set jpgFolder to make new folder at newFolder with properties {name:"jpg-pdf"} set mainFolder to make new folder at newFolder with properties {name:"main"} set printFolder to make new folder at mainFolder with properties {name:"• for printer"} set refverFolder to make new folder at newFolder with properties {name:"ref_ver"} set supportFolder to make new folder at newFolder with properties {name:"support"} end tell quit end buttonClick_ </code></pre> <p>Now I'm trying to have the app take "theLocation" folder alias and save it, so the next time the app launches it automatically chooses that folder as the save location without having to add it. I understand the logic that will go into it, but I can't figure out how to store/read information. I've tried tutorials on writing to the info.plist, but none of them have worked. Am I missing a basic piece of info on how applescript works?</p> <p>Thanks</p> <p>** Edit</p> <pre><code>script New_ProjectAppDelegate property parent : class "NSObject" property theTextField : missing value property theLocation : "" on applicationWillFinishLaunching_(aNotification) tell standardUserDefaults() of current application's NSUserDefaults registerDefaults_({theLocation:theLocation}) -- register the starting user default key:value items set theLocation to objectForKey_("theLocation") as text -- read any previously saved items (which will update the values) end tell end applicationWillFinishLaunching_ on buttonClick_(sender) if theLocation is "" then set theLocation to choose folder with prompt "Where to save your project?" tell standardUserDefaults() of current application's NSUserDefaults setObject_forKey_(theLocation, "theLocation") -- update the default items end tell else set theLocation to theLocation as text --display dialog theLocation as text end if tell application "Finder" set newFolder to make new folder at theLocation with properties {name:(theTextField's stringValue() as string)} set fontsFolder to make new folder at newFolder with properties {name:"fonts"} set jpgFolder to make new folder at newFolder with properties {name:"jpg-pdf"} set mainFolder to make new folder at newFolder with properties {name:"main"} set printFolder to make new folder at mainFolder with properties {name:"• for printer"} set refverFolder to make new folder at newFolder with properties {name:"ref_ver"} set supportFolder to make new folder at newFolder with properties {name:"support"} end tell quit end buttonClick_ on applicationShouldTerminate_(sender) tell standardUserDefaults() of current application's NSUserDefaults setObject_forKey_(theLocation, "theLocation") -- update the default items end tell return current application's NSTerminateNow end applicationShouldTerminate_ </code></pre> <p>end script</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload