use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
set myList to {"one", "two", "three"}
set oAns to choose from list myList ¬
with title ¬
"Choose One" with prompt ¬
"This window should have focus" default items ¬
"one" OK button name ¬
"Select" cancel button name ¬
"Cancel" multiple selections allowed false ¬
without empty selection allowed
set resultStr to item 1 of oAns
return resultStr
When I use an AppleScript prompt like you seem to be wanting, it’s done using System Events.
tell application "System Events"
set frontProcess to the name of every process whose frontmost is true
end tell
tell application "System Events"
activate
set theList to {"InDesign", "Photoshop", "Acrobat Pro", "----------", "Font Guide", "PMS Chart 1", "PMS Chart 2", "----------", "Colorate", "ColorSchemer", "----------", "Shrink It"}
choose from list theList with prompt "Design selections:" default items {"InDesign"}
set listchoice to result as text
end tell
if listchoice is "InDesign" then
do shell script "open -a 'Adobe InDesign CS5.5.app'"
else if listchoice is "Photoshop" then
do shell script "open -a 'Adobe Photoshop CS5.1.app'"
else if listchoice is "Acrobat Pro" then
do shell script "open -a 'Adobe Acrobat Pro.app'"
else if listchoice is "PMS Chart 1" then
tell application "Finder" to open POSIX file "/path/to/file"
else if listchoice is "PMS Chart 2" then
tell application "Finder" to open POSIX file "/path/to/file"
else if listchoice is "Colorate" then
tell application "Colorate"
activate
end tell
else if listchoice is "ColorSchemer" then
tell application "ColorSchemer Studio 2"
activate
end tell
else if listchoice is "Shrink It" then
tell application "ShrinkIt"
activate
end tell
else if listchoice is "Font Guide" then
tell application "Finder" to open POSIX file "/path/to/file"
else
activate frontProcess
end if
end
You used to have to tell-app-block<Interactive AppleScript Code>end-block in order to get a dialog to show up when running AppleScript from Keyboard Maestro.
Using System Events isn’t really a good idea, because it leaves System Events as the active app. Since System Events is a faceless background app the user is left in limbo. Although it appears they are actively in the “frontmost” app in reality they’re stuck in System Events.
A better method is to use the frontmost app itself for the interactive call, since this dumps the user right back where they started.
------------------------------------------------------------
try
set frontApp to path to frontmost application as text
set myList to {"one", "two", "three"}
tell application frontApp
set oAns to choose from list myList ¬
with title ¬
"Choose One" with prompt ¬
"This window should have focus" default items ¬
"one" OK button name ¬
"Select" cancel button name ¬
"Cancel" multiple selections allowed false ¬
without empty selection allowed
end tell
set resultStr to item 1 of oAns
return resultStr
on error e number n
if n = -128 then
# NULL
else
error e number n # Build your own error-handler.
end if
end try
------------------------------------------------------------