I don’t know how to get Dashboard client names (though I’ll explore that), but in the meantime, a much nicer way to get the list of all running processes is this:
tell application "Finder" to set process_list to (name of every process)
And, if you want only the visibles or invisibles, this:
on getProcesses(CanSee)
tell application "System Events"
set procs to get processes whose visible = CanSee
set proclist to {}
repeat with proc in procs
set end of proclist to (name of proc)
end repeat
end tell
return proclist
end getProcesses
set myVisibles to getProcesses(true)
set myInvisibles to getProcesses(false)
{myVisibles, myInvisibles}
On my machine (running 10.4.6), this script will list all the dashboard widgets in use:
set db to paragraphs of (do shell script "defaults read ~/Library/Preferences/com.apple.dashboard | grep -A 1 in-layer")
set wgts to {}
repeat with aP in db
if aP contains "path" then set end of wgts to word -2 of aP
end repeat
wgts
set wgts to {}
try
set db to paragraphs of (do shell script "defaults read ~/Library/Preferences/com.apple.dashboard | grep -A 1 in-layer")
repeat with aP in db
if aP contains "path" then set end of wgts to word -2 of aP
end repeat
end try
if wgts is {} then
display dialog "There are no Widgets currently running"
else
display dialog "Here are the Widgets currently running: " & return & return & wgts
end if
this just makes it a little more user friendly for me. i know yours was just an example of how to do it.
oh, and for the OP–>unfortunately the Widgets do not get their own process (they all run under ‘DashboardClient’) you won’t be able to view them with top. you might be able to grep a ps, but this seems a bit easier.
set wgts to {}
try
set db to paragraphs of (do shell script "defaults read ~/Library/Preferences/com.apple.dashboard | grep -A 1 in-layer")
repeat with aP in db
if aP contains "path" then set end of wgts to word -2 of aP
end repeat
end try
if wgts is {} then
display dialog "There are no Widgets currently running"
else
set w to ""
repeat with aW in wgts
set w to w & aW & return
end repeat
display dialog "Here are the Widgets currently running: " & return & return & w
end if
Now if I only understood the man pages for defaults, I could probably extract those keys directly.
Adam, your script only gets the last word and so returns decapitiated widget names for me.
Here is an improvement:
on listRunningUsersWidgets()
-- (Edit) old: set db to do shell script "defaults read ~/Library/Preferences/com.apple.dashboard | grep -A 1 in-layer | grep path"
set db to do shell script "defaults read ~/Library/Preferences/com.apple.dashboard layer-gadgets | grep path"
set l to {}
set text item delimiters to "/"
repeat with i in paragraphs of db
-- Remove extension of name part of path
set end of l to text 1 thru -6 of text item -2 of contents of i
end repeat
set text item delimiters to ""
return l
end listRunningUsersWidgets
listRunningUsersWidgets()
It may be worth noting that System Events’ Property List Suite can handle extraction without resorting to parsing:
tell application "System Events" to tell property list file ((path to preferences as Unicode text) & "com.apple.dashboard.plist")
set l to value of property list item "path" of property list items of property list item "layer-gadgets"
repeat with i in l
set i's contents to value of property list item "label" of ¬
(property list item 1 of property list item "widget-list" where i is in value)
end repeat
end tell
l
I knew you would find out how to do it using that method, kai. (A clever was of doing it that way, looking closer)
It is quite ideal, because this is a new feature in Tiger (AppleScript 1.10) and so are Dashboard widgets.
Just a query kai, how do you find out the correct values for the property list items (the structuring and naming). Do you use Property List Editor, or is there some way of viewing/browsing using AppleScript?
Let me second QD’s query, Kai. I knew there had to be a way and was aware of System Events’ capabilities in that regard, but hadn’t a clue what the names of the parts I wanted were. Now, looking at com.apple.dashboard.plist in the Property List Editor (part of Developer), I see “in-layer” and “path” as properties of the “dictionary” of item 0 of “layer-gadgets”, where in-layer tells us that it’s active (boolean = true) and path includes the name. At the bottom of the listing there is also a “widget-list”, but the line below completely defeats me because the widget-list includes widgets that aren’t “on”:
set i's contents to value of property list item "label" of ¬
(property list item 1 of property list item "widget-list" where i is in value)
Hi Adam, I understand a little of kai’s script.
It extracts the path for every item “layer-gadgets”, which is a list of all the users open widgets, but doesn’t include a name/label. It then compares this path to “widget-list”, which contains the path and name/label for every widget installed, and finds out which one has the same path so the name can be found. (This was discovered after browsing with Property List Editor)
It is superior to our scripts, because it gets the localised name for the widget, and not the one off the actual widget file’s disk name. For example, if the developer was lazy, a widget file could be named “MCW 1.1” on disk, but in the Dashboard the name displayed is actually “My Cool Widget”.
– However –
However, although I seem to remember kai’s script working for me at first (read: I’m not actually sure if I did run once with no problems), it certainly doesn’t now. It breaks on getting the path for “layer-gadgets”. Looking at the file with P.L.E., I find an item for a widget without a path. Yes, as you might’ve guessed, I have Apple’s widget manager thingy open. (why? because that thing at the bottom that convientely pushes all my widget’s upwards out of sight is actually a bit hard to read with its flurry of icons and mesh background. I think the dots make it harder to focus with than a uniform slab of colour.)
So I guess one option would be to loop through all the items making sure a path exists for that item, and ignoring it if it doesn’t (or supplying a name like “Apple’s widget manager thingy”). Or do I have a feeling that kai might have some other tricks up his sleeve?
Spot on, Qwerty - thanks for saving me an explanation. (Incidentally, in answer to your earlier question, I generally check the structure of a property list file using Property List Editor, too.)
Now what might give you that impression, Qwerty?
I hadn’t tried the script with Widget Manager open - and that possibility certainly does require some additional consideration. However, I think we might be able to avoid another loop with a little judicious filtering:
tell application "System Events" to tell property list file ((path to preferences as Unicode text) & "com.apple.dashboard.plist")
set l to value of property list item "path" of (property list items of ¬
property list item "layer-gadgets" where "path" is in name of property list items)
repeat with i in l
set i's contents to value of property list item "label" of (property list item 1 ¬
of property list item "widget-list" where i is in value)
end repeat
if (count property list items of property list item "layer-gadgets") > ¬
(count l) then set l's end to "Widget Manager" (* optional line *)
end tell
l
On my 10.4.6 machine, the “Widget Manager” is never added whether open or not. I tested with the dashboard frontmost using a hotkey to trigger the script. Otherwise, thanks to Querty & Kai for the explanation.
Nope - I’ve mainly archived and installed, too. I didn’t run the script with dashboard frontmost - and I also found it necessary to wait a few moments between opening/dismissing Widget Manager before running it. But given those caveats, it works consistently here.
FWIW, I too have 10.4.6 installed, but since the Dashboard app and its associated preferences are new to Tiger, I don’t think that the different install methods would matter. Have you tried restarting and then moving the ‘com.apple.dashboard’ file out of your preferences folder so a fresh one is created?