|
|
#1 |
|
Hall of Famer
Join Date: Oct 2002
Location: Halifax, Canada
Posts: 4,948
|
Apps Running
Command-Tab presents a view of the GUI apps that are currently running
Is there an way to get a list of the apps that appear there in an AppleScript or shell script?
__________________
17" MBP, OS X 10.8.3; 27" iMac, OS X 10.8.3 |
|
|
|
|
|
#2 |
|
All Star
Join Date: May 2004
Location: london on ca
Posts: 930
|
I don't know if it will get them all, but how about something like this for starters...
Code:
tell application "System Events" -- visible apps set theList to name of processes whose visible is true -- normally visible but "hidden" apps that still appear in Cmd-Tab set notvisibles to name of processes whose visible is false repeat with currentProcess in notvisibles set itsproperties to properties of process currentProcess if (background only) of itsproperties is false then set theList to theList & currentProcess end if end repeat end tell set result to theList Code:
tell application "System Events" to set theList to name of processes whose background only is false Last edited by biovizier; 08-05-2009 at 11:28 AM. |
|
|
|
|
|
#3 |
|
Hall of Famer
Join Date: Oct 2002
Location: Halifax, Canada
Posts: 4,948
|
Thanks for the response Biovizier. After playing with it for a few minutes, I realized that I had not asked the question intelligently (completely off the mark, in fact).
I have a JavaScript called "Readability"** that produces a configurable large page of the main event on a web page with surprising accuracy. I like to use it reading newspaper articles and NetNewsWire feeds, and it works with either. Because I'm a keyboard command fan I often run scripts from Quicksilver and I'd like the script to target either Safari or NetNewswire, whichever has the frontmost window (the one I want to read). I haven't found a clean way to do that. _________ ** Readability comes as a link to be dragged to the Bookmarks Bar of a browser, but having done that, you can copy the JavaScript from the bookmark for use in an AppleScript like this (with either Safari or NetNewsWire in the tell): tell application "NetNewsWire" to tell document 1 to do JavaScript "......"
__________________
17" MBP, OS X 10.8.3; 27" iMac, OS X 10.8.3 |
|
|
|
|
|
#4 | |||||||||||||||||||||||
|
All Star
Join Date: May 2004
Location: london on ca
Posts: 930
|
Hmm, that sounds like a tough one... I see other properties that can be tested for processes, such as "frontmost" or "focused" (this one seems to be "missing value" for everything) that might work for the active app, but unless one or the other is actually the active application, I can't think of a way to determine which one is closer to the front (i.e. whose icon is closer to the left in Cmd-Tab) either... |
|||||||||||||||||||||||
|
|
|
|
|
#5 |
|
Hall of Famer
Join Date: Oct 2002
Location: Halifax, Canada
Posts: 4,948
|
I eventually came up with this, Biovizier:
set JS to "javascript "tell document 1 of application last_app to do JavaScript ..." wouldn't compile for some reason.
__________________
17" MBP, OS X 10.8.3; 27" iMac, OS X 10.8.3 |
|
|
|
|
|
#6 |
|
Hall of Famer
Join Date: Apr 2007
Posts: 4,262
|
just as a matter of sanity, you can write Nova's script as follows:
Code:
set JS to "readStyle='style-novel';
readSize='size-large';
readMargin='margin-wide';
_readability_script=document.createElement('SCRIPT');
_readability_script.type='text/javascript';
_readability_script.src='http://lab.arc90.com/experiments/readability/js/readability.js?x='+(Math.random());
document.getElementsByTagName('head')[0].appendChild(_readability_script);
_readability_css=document.createElement('LINK');
_readability_css.rel='stylesheet';
_readability_css.href='http://lab.arc90.com/experiments/readability/css/readability.css';
_readability_css.type='text/css';
_readability_css.media='screen';
document.getElementsByTagName('head')[0].appendChild(_readability_css);
_readability_print_css=document.createElement('LINK');
_readability_print_css.rel='stylesh eet';
_readability_print_css.href='http://lab.arc90.com/experiments/readability/css/readability-print.css';
_readability_print_css.media='print';
_readability_print_css.type='text/css';
document.getElementsByTagName('head')[0].appendChild(_readability_print_css);"
tell application "System Events" to set last_app to item 1 of (get name of processes whose frontmost is true)
if last_app is "Safari" then
tell document 1 of application "Safari" to do JavaScript JS
else if last_app is "NetNewsWire" then
tell document 1 of application "NetNewsWire" to do JavaScript JS
else
beep 3
end if
__________________
Philosophy is a battle against the bewitchment of our intelligence by means of language. -LW- |
|
|
|
|
|
#7 |
|
Hall of Famer
Join Date: Oct 2002
Location: Halifax, Canada
Posts: 4,948
|
Perfectly acceptable to NetNewsWire (as I suspected). I've made the change in my script to enhance its readability :-)
Thanks
__________________
17" MBP, OS X 10.8.3; 27" iMac, OS X 10.8.3 Last edited by NovaScotian; 08-06-2009 at 08:42 AM. |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|