Re: Better Open Dictionary
Re: Better Open Dictionary
- Subject: Re: Better Open Dictionary
- From: has <email@hidden>
- Date: Thu, 6 Mar 2003 18:40:13 +0000
John Delacour wrote:
[snip Nathan's script]
I'm afraid I just don't bother to read these verbose scripts.
Applescript is naturally verbose but that's no reason to quintuple
its verbosity.
Yeah, but be fair, John; not everyone on this list is a total
scripting wizard like you are. Else it'd be called "The AppleScript
Illuminati Mailing List" or something. Writing really tight,
efficient code ain't something you get good at overnight, and plenty
folk are still learning. And it's not like there's tons of good
documentation and AppleScript literature to make this easy. So that's
why they're here.
A script to open the dictionary of current processes need be no
longer than this, and it's very fast:
tell app "System Events"
set _apps to name of processes whose has scripting terminology is true
tell me to set _list to choose from list _apps default items first
item of _apps with prompt "Open the dictionary for..." -- !! LONG LINE
if _list is in {false} then return
set _app to file of process (first item in the _list)
tell me to open _app
end
Did the 'has scripting terminology' reference filter work for you?
OMM (OS10.2.3, AS1.9.1) I get a lot of bad 'false' values - out of a
dozen scriptable apps running only four actually showed in the
dialog. (Bug?)
Anyway, here's a short, fast script that replicates Nathan's original
by allowing multiple files to be opened at once:
======================================================================
tell application "Finder" to set appNames to name of application
[NO-BREAK]processes whose (visible is true) or (name is "System Events")
set appsToOpen to choose from list appNames with multiple selections
[NO-BREAK]allowed without empty selection allowed
if appsToOpen is not {false} then
set appsList to {}
repeat with anApp in appsToOpen
set appsList's end to path to application (anApp's contents)
end repeat
tell application "Script Editor" to open appsList
end if
======================================================================
Uses a Finder filter reference to get a list of process names (no
loop required), and Standard Additions' 'path to' command to get the
full path to each selected app one at a time. I could've opened each
file individually from inside the loop, but in the interests of going
slightly faster it builds a list of files and then opens the lot in a
single 'open' command.
I've retained the 'visible is true' filter because of the problem I
had with 'has terminology'. This has fairly horrid results if you
select non-scriptable apps, but I can't think of a better solution
(other than file another bug report on 'has scripting terminology'
and hope it's fixed eventually).
It would be nice to use a fancy Finder construct, 'application file
of every application process whose name is in appsToOpen as alias
list' to get a list of aliases to the selected files in a single pop.
But Finder's filter references aren't powerful enough to handle lists
of names and there's a couple of bugs in it anyway, so a loop it is.
A further improvement would be to sort the appNames list before
displaying in the dialog, but I don't have a compact sort handler to
paste in here so you can find your own.
HTH
has
--
http://www.barple.pwp.blueyonder.co.uk -- The Little Page of AppleScripts
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.