Hey guys, I’m trying to make a simple application in applescript studio
on launched theObject
tell window 1
set title of button "button1" to "Cancel"
set title of button "button2" to "Emulate"
set thePopupItems to {"Call of Duty SP", "Call of Duty MP", "WoW", "Call of Duty 4 SP", "Call of Duty 4 MP"}
tell menu of popup button 1
delete every menu item
repeat with aMenuItem in thePopupItems
make new menu item at end of menu items with properties {title:aMenuItem}
end repeat
end tell
end tell
end launched
on clicked theObject
if title of theObject = "Cancel" then
quit
else if title of theObject = "Emulate" then
display dialog "Now emulating NAME OF CHOOSEN POPUP MENU ITEM HERE"
open application /Resources/emus/NAME OF CHOSEN POPUP MENU ITEM HERE.app
end if
end clicked
on choose menu item theObject
delay 0.05
end choose menu item
I can’t figure out how to get the returned result from the popup menu, also is it possible to open an application from inside this applications resorces folder?
Thanks in advance JDogg
try this, the on choose menu handler is not necessary
on launched theObject
tell window 1
set title of button "button1" to "Cancel"
set title of button "button2" to "Emulate"
set thePopupItems to {"Call of Duty SP", "Call of Duty MP", "WoW", "Call of Duty 4 SP", "Call of Duty 4 MP"}
tell menu of popup button 1
delete every menu item
repeat with aMenuItem in thePopupItems
make new menu item at end of menu items with properties {title:aMenuItem}
end repeat
end tell
end tell
end launched
on clicked theObject
if title of theObject = "Cancel" then
quit
else if title of theObject = "Emulate" then
set currentMenuItem to title of current menu item of popup button 1 of window 1
display dialog "Now emulating " & currentMenuItem
activate application ((path to me as text) & "Contents:Resources:emus:" & currentMenuItem & ".app")
end if
end clicked
(*
on choose menu item theObject
delay 0.05
end choose menu item
*)
Thank you so much!, worked 100%. Another quick question, lets say I wanted to make a button appear AFTER the user hits the “emulate” button, once that button is pressed the application (the one in the resources folder)would quit.
Also if possible, once the application is launched, it is automatically hidden (the emulation apps have no gui)
on launched theObject
tell window 1
set title of button "button1" to "Cancel"
set title of button "button2" to "Emulate"
set title of button "button3" to "Stop Emulation"
set thePopupItems to {"Call of Duty SP", "Call of Duty MP", "WoW", "Call of Duty 4 SP", "Call of Duty 4 MP"}
tell menu of popup button 1
delete every menu item
repeat with aMenuItem in thePopupItems
make new menu item at end of menu items with properties {title:aMenuItem}
end repeat
end tell
end tell
end launched
on clicked theObject
if title of theObject = "Cancel" then
quit
else if title of theObject = "Emulate" then
set currentMenuItem to title of current menu item of popup button 1 of window 1
display dialog "Now emulating " & currentMenuItem
activate application ((path to me as text) & "Contents:Resources:emus:" & currentMenuItem & ".app"
end if
what’s about this, launch just launches the application without bringing it to the front.
on launched theObject
tell window 1
set title of button "button1" to "Cancel"
set title of button "button2" to "Emulate"
set title of button "button3" to "Stop"
set visible of button "button3" to false
set thePopupItems to {"Call of Duty SP", "Call of Duty MP", "WoW", "Call of Duty 4 SP", "Call of Duty 4 MP"}
tell menu of popup button 1
delete every menu item
repeat with aMenuItem in thePopupItems
make new menu item at end of menu items with properties {title:aMenuItem}
end repeat
end tell
end tell
end launched
on clicked theObject
if title of theObject = "Cancel" then
quit
else if title of theObject = "Emulate" then
set currentMenuItem to title of current menu item of popup button 1 of window 1
display dialog "Now emulating " & currentMenuItem
launch application ((path to me as text) & "Contents:Resources:emus:" & currentMenuItem & ".app")
tell button "button3" of window 1
set title to "Stop " & currentMenuItem
set visible to true
end tell
else if name of theObject = "button3" then
quit application ((path to me as text) & "Contents:Resources:emus:" & currentMenuItem & ".app")
set visible of button "button3" of window 1 to false
end if
end clicked
^ Script works fine, however it wont quit the application it launches :(. Say I choose Call of Duty MP, it launches fine, but when I hit stop nothing happens
on launched theObject
tell window 1
set title of button "button1" to "Quit"
set title of button "button2" to "Emulate"
set title of button "button3" to "Stop"
set thePopupItems to {"Call of Duty SP", "Call of Duty MP", "WoW", "Call of Duty 4 SP", "Call of Duty 4 MP"}
tell menu of popup button 1
delete every menu item
repeat with aMenuItem in thePopupItems
make new menu item at end of menu items with properties {title:aMenuItem}
end repeat
end tell
end tell
end launched
on clicked theObject
if title of theObject = "Quit" then
quit
else if title of theObject = "Emulate" then
set currentMenuItem to title of current menu item of popup button 1 of window 1
display dialog "Now emulating " & currentMenuItem
launch application ((path to me as text) & "Contents:Resources:emus:" & currentMenuItem & ".app")
tell button "button3" of window 1
set title to "Stop " & currentMenuItem
set visible to true
end tell
else if name of theObject = "Stop" then
quit application currentMenuItem & ".app"
end if
end clicked
in my origin script above the button “button3” is invisible by default,
and not until clicking the button “Emulate” defines the variable and makes the “Stop” button visible.
You changed that!
A different solution is to set the variable at the beginning of the handler,
but the disadvantage is, the user can change the popup menu and maybe the chosen application doesn’t run at all
on clicked theObject
set currentMenuItem to title of current menu item of popup button 1 of window 1
if title of theObject = "Quit" then
quit
else if title of theObject = "Emulate" then
display dialog "Now emulating " & currentMenuItem
launch application ((path to me as text) & "Contents:Resources:emus:" & currentMenuItem & ".app")
tell button "button3" of window 1
set title to "Stop " & currentMenuItem
set visible to true
end tell
else if name of theObject = "button3" then
quit application currentMenuItem
end if
end clicked
Thank you sir!!!. Sorry for changing the script around :P. Works 100% thank you thank you. I will give you credit when I release the application on my website
I lost the files :(. I used bits and pieces from the forum, all works fine EXCEPT, doesn’t quit the applications
on launched theObject
tell window 1
set title of button "button1" to "Cancel"
set title of button "button2" to "Emulate"
set title of button "button3" to "Stop"
set visible of button "button3" to false
set thePopupItems to {"Call of Duty SP", "Call of Duty MP", "WoW", "Call of Duty 4 SP", "Call of Duty 4 MP"}
tell menu of popup button 1
delete every menu item
repeat with aMenuItem in thePopupItems
make new menu item at end of menu items with properties {title:aMenuItem}
end repeat
end tell
end tell
end launched
on clicked theObject
set currentMenuItem to title of current menu item of popup button 1 of window 1
if title of theObject = "Quit" then
quit
else if title of theObject = "Emulate" then
display dialog "Now emulating " & currentMenuItem
launch application ((path to me as text) & "Contents:Resources:emus:" & currentMenuItem & ".app")
tell button "button3" of window 1
set title to "Stop " & currentMenuItem
set visible to true
end tell
else if name of theObject = "button3" then
quit application currentMenuItem
end if
end clicked