Hi there, Is there a way for when I start typing the options in the list reduce to the options contains text of the text field?
ie: “201”
result: “tape delay 201”
or
text entered: “even”
result
“Eventide Harmoniser H 910”
“Eventide Blackhole”
“Eventtide Ultrachanel”
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use framework "Appkit"
use framework "Cocoa"
use scripting additions
property SYS_RESOURCES : "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/"
property response : missing value -- this will be the button pressed in the alert
on run
set theFolder to "HD:Users:me:Desktop:tests:trackFx:" as alias
tell application "System Events" to set theList to name of files of theFolder
try
set choice to (showAlert given parameters:{message:"Choose from List", info:("Names of folders from " & quoted form of POSIX path of theFolder & ":"), choices:theList})
if choice is not "" then tell application "Finder"
activate
set thePlug to file choice of folder theFolder as «class furl»
run script thePlug
end tell
on error errmess number errnum
tell me to activate
log "Error " & errnum & ": " & errmess
display alert "Error " & errnum message errmess
end try
end run
###########################################
# NSAlert creation and display stuff
###########################################
# create a base alert object and its accessoryView combo box
to createAlert()
set alert to (current application's NSAlert's alloc's init())
repeat with anItem in {"Choose", "Cancel"} -- arbitrary, from right to left
(alert's addButtonWithTitle:anItem)
end repeat
tell ((current application's NSComboBox)'s alloc's initWithFrame:{{0, 0}, {298, 28}})
set alert's |window|'s initialFirstResponder to it -- select the text field
set its hasVerticalScroller to true
set its completes to true -- matches an item while manually entering
set its numberOfVisibleItems to 10 -- arbitrary
set its placeholderString to "Enter or select an item" -- arbitrary
alert's setAccessoryView:it
end tell
return alert
end createAlert
# configure and show an alert
# the arguments parameter is a record of options that is merged with defaults
to showAlert given parameters:parameters
set parameters to parameters & {message:""} & {info:""} & {icon:""} & {choices:{}} -- defaults
set alert to createAlert()
alert's setMessageText:(message of parameters)
alert's setInformativeText:(info of parameters)
my setIcon:(icon of parameters) forAlert:alert
set comboList to {}
repeat with anItem in (choices of parameters) -- populate accessoryView combo box
set anItem to contents of anItem
if anItem is not "" and comboList does not contain anItem then -- filter blanks and duplicates
((alert's accessoryView)'s addItemWithObjectValue:anItem)
set end of comboList to anItem
end if
end repeat
my performSelectorOnMainThread:"performAlert:" withObject:alert waitUntilDone:true
if response is (current application's NSAlertSecondButtonReturn) then error number -128 -- Cancel
return alert's accessoryView's stringValue as text
end showAlert
# used by showAlert via performSelectorOnMainThread - when running a script from the
# Script Editor or Script Debugger, an NSAlert needs be set to run on the main thread
on performAlert:alert
set my response to alert's runModal()
end performAlert:
# set the alert icon
# the iconType argument can be "critical", "informational", or "warning",
# the "Note", "Caution", or "Stop" system icons, or a POSIX image file
to setIcon:iconType forAlert:alert
set iconImage to missing value
if iconType is "critical" then
alert's setAlertStyle:(current application's NSCriticalAlertStyle)
else if iconType is in {"", "informational", "warning"} then
alert's setAlertStyle:(current application's NSInformationalAlertStyle)
else if iconType is in {"Note", "Caution", "Stop"} then -- system icon
set iconImage to current application's NSImage's alloc's initWithContentsOfFile:(SYS_RESOURCES & "Alert" & iconType & "Icon.icns")
else -- icon or image from a file
set iconImage to current application's NSImage's alloc's initWithContentsOfFile:iconType
end if
if iconImage is not missing value then set alert's icon to iconImage
end setIcon:forAlert: