Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

codemonkeypete

macrumors newbie
Original poster
Dec 9, 2005
2
0
Hi, I am an extreme noob when it comes to developing in Mac,so i could really use as much help on my first project as I can get! :eek:
Ok, so here is the plan: I would like to create a script or small application that takes a list of all the applications currently open in the dock, and outputs that list to a text file.(could be saved as .txt, .xml or .rtf)......while the application/script is running, it would need to repeat this function every 30 minutes...

Basically, what I am wanting to do is create a little app that I will run on my website, that displays a list of the apps currently running on my mac :)

I am a seasoned Flash Actionscripter, so getting the list to display on the web automatically is no problem(using flash8, we can now do time based automatic uploading and/or downloading ;) ). ... oh, as a possible extra feature to this script, i wouldnt mind(if its too tricky, doesnt matter) doing the same thing with a desktop screengrab... auto save to jpg/png every hr.

Could anybody spare the time to help me with :
a) either the entire script/app or
b) links to a good starting point for me or
c) advice on where to begin, and if this is even possible?

Thanks Heaps in advance.
 

savar

macrumors 68000
Jun 6, 2003
1,950
0
District of Columbia
codemonkeypete said:
c) advice on where to begin, and if this is even possible?

Thanks Heaps in advance.

Pete,

I can help you out on part c. Its probably impossible. I used to maintain a Dock switcher application (one of out the ~2,000 that existed at one point) and I can tell you there is very little in the public Dock API, and nothing which does what you're wanting to do. However, I can offer a few [helpful?] comments:

1) You can read the Dock preferences file in ~/Library/Preferences/com.apple.Dock.plist, inside that file you'll be able to see what applications are permanently stored in the Dock. (Not what you want to do, though.)

2) There is an API to access features of the Dock, its just not public. I found a file once where somebody had reverse engineered some of the function calls. I don't think there was a call to see what items were open in the dock, however. I don't have it bookmarked but its called CGSPrivate.h, you can find it on Google hopefully.

3) The good news: I don't think you need the Dock to what you're trying to do. Instead, you just need to look at the running processes on your machine, which can be done in a number of ways unrelated to the dock, varying in difficulty and effectiveness. One [relatively] simple way would be to call "ps aux" in the Terminal, and filter that list for only processes which have a psn flag (perhaps with grep). A better idea would be to use the Carbon Process Manager to iterate a list of processes. There are quite a few tutorials for doing this online.

Email me (mehaase@gmail) if you have more questions. If you've not done any Carbon/Cocoa you might get in over your head pretty quickly.
 

superbovine

macrumors 68030
Nov 7, 2003
2,872
0
You didn't say what language you wanted the script in. I probably wouldn't have wrote the entire thing anyways, since you are a CODEMONKEY. For the most part through from PHP or PERL you can call unix commands.

from terminal type

Code:
cow@supercow cow $ps -A
 PID  TT  STAT      TIME COMMAND
    1  ??  S<s    0:04.97 /sbin/launchd
   23  ??  Ss     0:00.44 /sbin/dynamic_pager -F /private/var/vm/swapfile
   27  ??  Ss     0:03.89 kextd
   31  ??  Ss     4:27.93 /usr/sbin/configd
   32  ??  Ss     0:13.15 /usr/sbin/coreaudiod
   33  ??  Ss     0:05.34 /usr/sbin/diskarbitrationd
   34  ??  Ss     0:00.12 /usr/sbin/memberd -x
   35  ??  Ss     0:04.52 /usr/sbin/securityd
   37  ??  Ss     0:02.09 /usr/sbin/notifyd
   38  ??  Ss     0:24.93 /usr/sbin/DirectoryService
   39  ??  S      0:00.49 /usr/sbin/blued
   41  ??  Ss     0:00.04 /usr/sbin/KernelEventAgent
   42  ??  Ss     0:05.38 /usr/sbin/mDNSResponder -launchdaemon
   43  ??  Ss     0:06.85 /usr/sbin/netinfod -s local
   44  ??  Ss     0:00.88 /usr/sbin/syslogd
   49  ??  Ss     2:08.46 /usr/sbin/update
   60  ??  Ss   101:26.27 /System/Library/Frameworks/ApplicationServices.framework/Frameworks/CoreGraphics.framework/Resources/WindowServer -daemon
   61  ??  Ss     0:06.47 /usr/sbin/distnoted
   62  ??  Ss     1:28.18 /System/Library/CoreServices/coreservicesd
   64  ??  Ss     0:47.21 /System/Library/Frameworks/ApplicationServices.framework/Frameworks/ATS.framework/Support/ATSServer
   65  ??  Ss     0:13.04 /System/Library/CoreServices/loginwindow.app/Contents/MacOS/loginwindow console
   96  ??  Ss     0:00.02 /usr/libexec/crashreporterd
   99  ??  Ss     0:14.40 ntpd -f /var/run/ntp.drift -p /var/run/ntpd.pid
  113  ??  Ss     0:00.00 nfsiod -n 4
  122  ??  Ss     0:00.00 rpc.lockd -w
  125  ??  Ss     0:13.15 /usr/sbin/automount -f -m /Network -nsl -mnt /private/var/automount
  152  ??  Ss     4:50.98 /System/Library/Frameworks/CoreServices.framework/Frameworks/Metadata.framework/Versions/A/Support/mds
  166  ??  Ss     0:00.21 /usr/sbin/automount -f -m /automount/Servers -fstab -mnt /private/Network/Servers -m /automount/static -static -mnt /private/var/automou
  171  ??  Ss     0:00.86 /System/Library/CoreServices/pbs
  177  ??  S      2:40.12 /System/Library/CoreServices/Dock.app/Contents/MacOS/Dock -psn_0_524289
  181  ??  S      1:11.08 /System/Library/CoreServices/SystemUIServer.app/Contents/MacOS/SystemUIServer -psn_0_655361
  182  ??  S      2:09.70 /System/Library/CoreServices/Finder.app/Contents/MacOS/Finder -psn_0_786433
  186  ??  S      0:00.49 /Applications/iTunes.app/Contents/Resources/iTunesHelper.app/Contents/MacOS/iTunesHelper -psn_0_917505
  187  ??  S      0:00.45 /Applications/Microsoft AutoUpdate.app/Contents/MacOS/Microsoft AU Daemon.app/Contents/MacOS/Microsoft AU Daemon -psn_0_1048577
  196  ??  S      0:05.74 /System/Library/Services/AppleSpell.service/Contents/MacOS/AppleSpell -psn_0_1703937
  267  ??  S      1:12.27 /Applications/Gmail Notifier.app/Contents/MacOS/Gmail Notifier -psn_0_4325377
  270  ??  S      0:02.47 /System/Library/CoreServices/Dock.app/Contents/Resources/DashboardClient.app/Contents/MacOS/DashboardClient /Library/Widgets/Dictionary.
  271  ??  S      0:09.08 /System/Library/CoreServices/Dock.app/Contents/Resources/DashboardClient.app/Contents/MacOS/DashboardClient /Users/cow/Library/Widgets/B
  272  ??  S      0:17.64 /System/Library/CoreServices/Dock.app/Contents/Resources/DashboardClient.app/Contents/MacOS/DashboardClient /Library/Widgets/Weather.wdg
  273  ??  S      5:42.11 /System/Library/CoreServices/Dock.app/Contents/Resources/DashboardClient.app/Contents/MacOS/DashboardClient /Library/Widgets/World Clock
  274  ??  S      0:03.32 /System/Library/CoreServices/Dock.app/Contents/Resources/DashboardClient.app/Contents/MacOS/DashboardClient /Library/Widgets/Calendar.wd
  275  ??  S      0:22.09 /System/Library/CoreServices/Dock.app/Contents/Resources/DashboardClient.app/Contents/MacOS/DashboardClient /Users/cow/Library/Widgets/N
  276  ??  S      5:32.46 /System/Library/CoreServices/Dock.app/Contents/Resources/DashboardClient.app/Contents/MacOS/DashboardClient /Library/Widgets/World Clock
  277  ??  S      0:09.26 /System/Library/CoreServices/Dock.app/Contents/Resources/DashboardClient.app/Contents/MacOS/DashboardClient /Users/cow/Library/Widgets/G
  278  ??  S      6:21.75 /System/Library/CoreServices/Dock.app/Contents/Resources/DashboardClient.app/Contents/MacOS/DashboardClient /Library/Widgets/World Clock
  284  ??  S      0:01.99 /System/Library/CoreServices/Dock.app/Contents/Resources/DashboardClient.app/Contents/MacOS/DashboardClient /Library/Widgets/Stickies.wd
 1309  ??  Ss     0:00.46 /usr/sbin/cupsd -f
 1473  ??  S      1:32.03 /Applications/Utilities/Terminal.app/Contents/MacOS/Terminal -psn_0_23461889
 1687  ??  S     41:45.72 /Applications/iTunes.app/Contents/MacOS/iTunes -psn_0_27787265
 2338  ??  S      0:06.16 /Applications/iChat.app/Contents/MacOS/iChat -psn_0_34865153
 2339  ??  Ss     0:01.36 /System/Library/Frameworks/InstantMessage.framework/iChatAgent.app/Contents/MacOS/iChatAgent
 2378  ??  R      6:53.26 /Applications/Firefox.app/Contents/MacOS/firefox-bin -psn_0_35913729
 2474  ??  S      0:00.86 /Applications/Preview.app/Contents/MacOS/Preview -psn_0_37617665
 2544  ??  Ss     0:00.98 /usr/sbin/lookupd
 2551  ??  S      0:32.39 /Applications/Microsoft Messenger.app/Contents/MacOS/Microsoft Messenger -psn_0_38010881
 2552  ??  S      0:10.81 /Applications/Microsoft Messenger.app/Contents/SharedSupport/Microsoft Messenger Daemon.app/Contents/MacOS/Microsoft Messenger Daemon -p
 2553  ??  SNs    0:01.02 /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/Metadata.framework/Versions/A/Support/mdimportserver
 2554  ??  S      0:03.47 /Applications/Microsoft Messenger.app/Contents/SharedSupport/Alerts Daemon.app/Contents/MacOS/Alerts Daemon -psn_0_38273025
 2555  ??  S      0:05.50 /Applications/Mail.app/Contents/MacOS/Mail -psn_0_38404097
 2557  ??  S      0:14.57 /Applications/thunderbird.app/Contents/MacOS/thunderbird-bin -psn_0_38535169
 2559  ??  S      0:27.25 /Applications/Microsoft Office 2004/Microsoft Entourage /Applications/Microsoft Office 2004/Microsoft Entourage -psn_0_38666241
 2560  ??  S      0:03.98 /Applications/Microsoft Office 2004/Office/Microsoft Database Daemon /Applications/Microsoft Office 2004/Office/Microsoft Database Daemo
 2563  ??  S      3:44.93 /Applications/Safari.app/Contents/MacOS/Safari -psn_0_38928385
 2483  p1  Ss     0:00.03 login -pf cow
 2484  p1  S      0:00.07 -bash
 2579  p1  R+     0:00.01 ps -A

This display all applications running including system apps.

To just get the application in the Dock, I assume that all the application the Dock are stored in /Applications directory.

Code:
cow@supercow cow $ps -A | grep 'Applications'
  186  ??  S      0:00.49 /Applications/iTunes.app/Contents/Resources/iTunesHelper.app/Contents/MacOS/iTunesHelper -psn_0_917505
  187  ??  S      0:00.45 /Applications/Microsoft AutoUpdate.app/Contents/MacOS/Microsoft AU Daemon.app/Contents/MacOS/Microsoft AU Daemon -psn_0_1048577
  267  ??  S      1:12.27 /Applications/Gmail Notifier.app/Contents/MacOS/Gmail Notifier -psn_0_4325377
 1473  ??  S      1:34.11 /Applications/Utilities/Terminal.app/Contents/MacOS/Terminal -psn_0_23461889
 1687  ??  S     41:46.63 /Applications/iTunes.app/Contents/MacOS/iTunes -psn_0_27787265
 2338  ??  S      0:06.16 /Applications/iChat.app/Contents/MacOS/iChat -psn_0_34865153
 2378  ??  S      6:53.70 /Applications/Firefox.app/Contents/MacOS/firefox-bin -psn_0_35913729
 2474  ??  S      0:00.86 /Applications/Preview.app/Contents/MacOS/Preview -psn_0_37617665
 2551  ??  S      0:33.83 /Applications/Microsoft Messenger.app/Contents/MacOS/Microsoft Messenger -psn_0_38010881
 2552  ??  S      0:11.30 /Applications/Microsoft Messenger.app/Contents/SharedSupport/Microsoft Messenger Daemon.app/Contents/MacOS/Microsoft Messenger Daemon -p
 2554  ??  S      0:03.48 /Applications/Microsoft Messenger.app/Contents/SharedSupport/Alerts Daemon.app/Contents/MacOS/Alerts Daemon -psn_0_38273025
 2555  ??  S      0:05.55 /Applications/Mail.app/Contents/MacOS/Mail -psn_0_38404097
 2557  ??  S      0:14.94 /Applications/thunderbird.app/Contents/MacOS/thunderbird-bin -psn_0_38535169
 2559  ??  S      0:27.76 /Applications/Microsoft Office 2004/Microsoft Entourage /Applications/Microsoft Office 2004/Microsoft Entourage -psn_0_38666241
 2560  ??  S      0:04.01 /Applications/Microsoft Office 2004/Office/Microsoft Database Daemon /Applications/Microsoft Office 2004/Office/Microsoft Database Daemo
 2563  ??  S      3:51.42 /Applications/Safari.app/Contents/MacOS/Safari -psn_0_38928385
 2583  p1  R+     0:00.00 grep Applications

Basically, you can call this command and dump the data into a text file or read in the data directly to your script.
 

codemonkeypete

macrumors newbie
Original poster
Dec 9, 2005
2
0
Thanks SuperBovine. Unfortunately for me, Perl is not really an option, and my Php knowledge is still fairly limited... I'm referred to as the 'codemonkey' at work because I am the resident Flash Actionscripter and htmHell coder for a graphic design firm(i work with 4 designers that have no clue about anything code)...anyway, thats good advice... Because I'm really only wanting to display active applications, Savar's advice sounds very understandable...Ive started learning cocoa, and I am a very good googler, so I guess I'm in for a few long nites of tutorial reading... Thanks heaps for including your email addie mate, don't be at all suprised if u get an email or 25 from me soon :p
I have also been reading up on possible solutions using Third party Flash Applications, and may have a possible solution in MDM's Zinc2 ( http://www.multidmedia.com) ...Now that I know that this could be a doer, I'm going to give it a real go... Thanks again guys, Very much appreciated.
 

superbovine

macrumors 68030
Nov 7, 2003
2,872
0
if you are serious about web design, I do suggest you learn php or perl. I don't think writing a cocoa app for this is the correct solution. You can also look like opensource solutions. I am sure there are php and perl apps out there to monitor status of servers. check http://sourceforge.net

PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head> </head>

<body>
</code>

<?php


$ps_path = '/bin/ps';
$grep_path = '/usr/bin/grep';
$cmd = "$ps_path -A | $grep_path 'Applications'";
//echo $cmd . "\n";
$output = shell_exec("$cmd");

echo $output;

?>
</code>

</body>

</html>
 

mj_1903

macrumors 6502a
Feb 3, 2003
563
0
Sydney, Australia
I would advise writing an itty bity Cocoa application that you then call with a script.

NSWorkspace has this tasty morsel which the Dock actually uses verbatim:

Code:
[[NSWorkspace sharedWorkspace] launchedApplications]
From there it is quite easy as you would just output that and call it via PHP.
 

mduser63

macrumors 68040
Nov 9, 2004
3,042
31
Salt Lake City, UT
This little AppleScript gets a list of the running applications that aren't in the background (ie. in the Dock). I'm not an expert on AppleScript, but it should be possible to write AppleScript that will talk to your webserver and do what you want to do.

Code:
set applist to {}
tell application "System Events"
	set applist to the name of every application process where it is not background only
	choose from list applist with prompt "These are the currently running applications:"
end tell
 

Sunrunner

macrumors 6502a
Nov 27, 2003
600
2
codemonkeypete said:
Hi, I am an extreme noob when it comes to developing in Mac,so i could really use as much help on my first project as I can get! :eek:
Ok, so here is the plan: I would like to create a script or small application that takes a list of all the applications currently open in the dock, and outputs that list to a text file.(could be saved as .txt, .xml or .rtf)......while the application/script is running, it would need to repeat this function every 30 minutes...

Basically, what I am wanting to do is create a little app that I will run on my website, that displays a list of the apps currently running on my mac :)

I am a seasoned Flash Actionscripter, so getting the list to display on the web automatically is no problem(using flash8, we can now do time based automatic uploading and/or downloading ;) ). ... oh, as a possible extra feature to this script, i wouldnt mind(if its too tricky, doesnt matter) doing the same thing with a desktop screengrab... auto save to jpg/png every hr.

Could anybody spare the time to help me with :
a) either the entire script/app or
b) links to a good starting point for me or
c) advice on where to begin, and if this is even possible?

Thanks Heaps in advance.


Interesting idea, but the key question remains to be answered.... WHY?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.