Saturday, November 18, 2017

#1 2011-08-12 06:27:02 pm

rfmusic
Member
Registered: 2011-07-30
Posts: 14

Connecting an Interface Builder window to the script

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!

Model: MacPro4.1
AppleScript: xcode 3.1.2
Browser: Firefox 5.0.1
Operating System: Mac OS X (10.5)

Offline

 

#2 2011-08-12 10:48:21 pm

rfmusic
Member
Registered: 2011-07-30
Posts: 14

Re: Connecting an Interface Builder window to the script

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

bb

Offline

 

#3 2011-08-13 02:50:20 am

rfmusic
Member
Registered: 2011-07-30
Posts: 14

Re: Connecting an Interface Builder window to the script

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

Applescript:


--i come here from another routine
on setoptions()
--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
           tell contents
               set terminal to value of property list item "Terminal" as string
           end tell
       end tell
   end tell
--changing checkbox inside option window accordingly
   if terminal is equal to "0" then
       tell optionpanel
           set state of button "terminalcheckbox" to false
       end tell
   else if terminal is equal to "1" then
       tell optionpanel
           set state of button "terminalcheckbox" to true
       end tell
   end if
--and now ?
--display panel optionpanel ->hangs
--how to call on clicked?
--anything else?
end setoptions

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?

thanks!!

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:

Applescript:

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" & " &"
       end if
       close panel (window of theObject)
   end if
end clicked

this way the other script will stay hanged until the panel closes smile i was near just needed some sleep tongue

Last edited by rfmusic (2011-08-13 09:06:39 am)

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)