Hi all, i’ve just started using Xcode/Applescript Studio so sorry for the newbie question
I’m “converting” my script editor application to this format because I would like to add an Option window for my app, now i have many consequent display dialogs for setting up options.
I’ve created a window under interface builder, problem is that i don’t know how to let the window be called from the applescript, all the examples i’ve found uses “on clicked” or has specific handlers that doesn’t fit to what i need.
i just want to be able to open that window using a simple applescript command like a “display dialog”, windows should have checkboxes and drop down menus configured like last time so i need some values to be sent to that window before opening, then script should be blocked like a standard display dialog until i click ok and new values will be sent back to the script
i think i will be able to manage handlers for checkboxes by myself once i’ll be able to link the window to the script, so basically, how do i have to set the window event handler and the applescript code to do as above? Any advice? thank you!
AppleScript: xcode 3.1.2
Browser: Firefox 5.0.1
Operating System: Mac OS X (10.5)
I’ve found some useful examples inside Developer/Examples/Applescript
“Display Panel” example does exactly what i’m searching for, so i hope i’m ok. sorry
ok i’ve talked too early!!
i’ve managed to open the window where i want and to change values of checkboxes/menus accordingly to my values, but now i need to click the “Ok” button and close the window, problem is that it calls the “on clicked” routine, but i’m in another routine, is it possible to go to the “on clicked” routine from another one?
this is a slice of my situation
--i come here from another routine
--opening options window
load nib "Options"
set optionpanel to window "Options"
--getting a value from preference file
tell application "System Events"
set the plistfile_path to (path to home folder as Unicode text) & "Library:Preferences:LameScriptDnDmp3.plist"
tell property list file plistfile_path
set terminal to value of property list item "Terminal" as string
--changing checkbox inside option window accordingly
if terminal is equal to "0" then
set state of button "terminalcheckbox" to false
else if terminal is equal to "1" then
set state of button "terminalcheckbox" to true
--and now ?
--display panel optionpanel ->hangs
--how to call on clicked?
Now i need this script to wait until i press the “Ok” button, i’m not able to do it, if i enable the Action from the button it writes me “on clicked”, that is in another place, and i don’t know how to jump there from here, i’ve tried also writing “display panel optionpanel” but scripts hangs, is it possible to let it check the Ok button click using “display panel” command ? else do i have to do another script that has only the “on clicked” routine? and how do i tell to the main script to wait while the other is saving new parameters and closing the window?
EDIT: Ok solved, i write just for information if someone else needs it:
i’ve added “display panel optionpanel” to the end of the script above, then i’ve created another script called options.applescript and i have linked the “Ok” button action event handler to the new script.
The script also send the new value back to the preference file:
on clicked theObject
if name of theObject is "optionokbutton" then
set terminal to state of button "terminalcheckbox" of window "Options" as string
if terminal is equal to "1" then
do shell script "defaults write LameDnDmp3 Terminal 1" & " &"
else if terminal is equal to "0" then
do shell script "defaults write LameDnDmp3 Terminal 0" & " &"
close panel (window of theObject)
this way the other script will stay hanged until the panel closes i was near just needed some sleep