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

Kyp

macrumors newbie
Original poster
Aug 25, 2013
27
0
Gulf of Mexico
Guys,
As I am new to the Mac world, I was wondering if maybe someone could lend a hand. I am wanting to create an apple script that would return the same listing sa if you were opening the "Force Quit" applet.
force-quit-applications-window-on-mac-os-x-10-6.png


I am not wanting to see the memory usage, or any other info except the opened applications that I can force quit if needed. My plan is to use the script to output to my geektool desktop. There are countless other geektool shell scripts that do something similar, however I just want a list of "Running Applications" that I've opened. Not system processes.

I hope that you guys understand what I am asking, and maybe someone has a script that they wouldn't mind sharing.
Thanks in advance,
Kyp
 
Code:
tell application "System Events" to set runningApps to get the name of every process whose background only is false
choose from list runningApps
 
Hey that's great. How would I get it to display the results in the scripteditor, rather than open the box with the list. I'm just looking for an output of the items, and not choosing from a list.
Thanks!
 
Exactly how do you want the list displayed by GeekTool?

This command-line produces a comma-separated list on a single line:
Code:
osascript -e 'tell app "System Events" to get the name of every process whose background only is false'
If you want something else, then post again with specifics about how you want it to appear.
 
Thanks for the reply.

I did figure out how to make it display the list of apps who's background is set to false.
Code:
tell application "System Events" to set runningApps to get the name of every process whose background only is false

But like you said, it list separated by comma.
How would I format the list to not have a comma, and the list would be down instead of a line. "one on top of the other"

Not only do I want to achieve this, I want to learn how to use apple scripts.
With that said, where do I start? There is sooo much on the net, i'm not sure where to start.

Thanks,
Kyp
 
Last edited:
But like you said, it list separated by comma.
How would I format the list to not have a comma, and the list would be down instead of a line. "one on top of the other"

This one liner will make the entries "one on top of the other" as you want...

Code:
osascript -e 'tell app "System Events" to get the name of every process whose background only is false'  | tr , '\n' | sed -e 's/^[ \t]*//'
 
Not only do I want to achieve this, I want to learn how to use apple scripts.
With that said, where do I start? There is sooo much on the net, i'm not sure where to start.
Start with an AppleScript tutorial.

Google search terms: applescript tutorial.

When I do the search, the first result is this:
http://www.macosxautomation.com/applescript/firsttutorial/

Another google search: applescript beginner


Have you done any tutorials at all? Which ones? Be specific: post a book title, author, and edition; or post a URL of websites.
 
Well guys, I haven't really read anything. I did do a search for Apple Scripts, how to, beginners, and so forth. Like I said, there was so darn much out there, just didn't know where to start. I have been a windows user since 3.11 and I am an automation tech 20yrs, however it has a language of it's own and nothing like the apple scripts. I daily use http://global.wonderware.com/EN/pages/default.aspx, and http://ab.rockwellautomation.com/programmable-controllers/controllogix but like I said, nothing like apple scripts. So with that, I do appreciate all the advise and instruction you guys provide. I will look into the link you chown33 provided.
Thanks guys,
Kyp
 
Well guys, I haven't really read anything. I did do a search for Apple Scripts, how to, beginners, and so forth. Like I said, there was so darn much out there, just didn't know where to start.

There is no one "best" place to start. Some things work for some people, other things work for other people. Often, the most important step is to do something, and see how it works for you. "Try it, see what happens" is something I post fairly often.

When asking questions about programming (which includes scripting), it's always a good idea to:
1. Describe your experience.
2. Describe your goal.
3. Be prepared to answer the question, "What have you tried?".
4. And for all the above: Be specific.

For example, it's still unclear to me exactly what your goal is. Your first post specifically referred to GeekTool, and later posts mentioned AppleScript. The thing is, GeekTool isn't really an AppleScript tool. Yes, it's possible to run AppleScripts, because AppleScripts can be run with the 'osascript' command. But GeekTool itself is in many ways a shell-script tool, specifically, a way to present shell-script output on one's desktop. So being specific about one's goal (or goals), both short-term (e.g. GeekTool) and long-term (e.g. AppleScript) can help us understand what you're looking for.

The same can be said about "What have you tried?". Being specific about what searches you've done, rather than vague "I looked in a lot of places", can help us advise where to look next. A lot of programming involves being very specific about exactly what the computer should do, so being specific is a fundamental programming skill.

Finally, a lot of people think AppleScript is a good way to start automating things, when Automator is actually a much better starting point. Automator allows you to arrange sequences of steps where the output of one becomes the input to the next. It also allows you to write scripts (AppleScript or shell script) that process files and folders dropped onto the receiving app. So for beginners, Automator may actually be a better way to start automating things than AppleScript, unless one has already determined through trial and error that Automator is incapable. And that comes back around to "What have you tried?". Try it, see what happens.

Worth reading:
http://www.mikeash.com/getting_answers.html
 
You are correct in every aspect. In my years programing in the field, I have came across many that wanted to learn, and had many questions.

Apple scripts, Geektool.
I was under the impression that I could call an apple script from a geeklet, however I found out that you can put the script directly into the shell and run it there instead of calling the script from another location. Not true in every case (from what I have read) but 95% of the time you can.

I am notorious for wanting to close apps that I am currently not using. I had to click on apple logo then on force quit in order to see if there was anything running. I had the idea of using the apple script to see the running apps if there were any. Here is the script I ended up using.
Code:
Echo "Open Apps:"
Echo "----------------"

osascript -e 'tell app "System Events" to get the name of every process whose background only is false'  | tr , '\n' | sed -e 's/^[ \t]*//' | sed "s/\Finder//g"

I hid "finder" cause it's always running.

So I am now on the hunt for the meaning of all these items. s / ^ [ \t] * / / ' |
and how to use the keyboard (mac) to get the special characters. I know "ASCII" I use them daily. Once again, I am totally new to this scripting language. I appreciate the links, and will continue my education.

Have a great evening,
Kyp
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.