• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: List of open applications
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: List of open applications


  • Subject: Re: List of open applications
  • From: Christopher Stone <email@hidden>
  • Date: Thu, 06 Sep 2012 07:43:11 -0500

On Sep 06, 2012, at 05:04, koenig.yvan <email@hidden> wrote:
Alas I get an odd behavior.
______________________________________________________________________

Hey Yvan,

Hmm.  After fiddling around a bit I got this to work quite reliably from FastScripts, from the Applescript Editor, and from Script Debugger.

If you run it from the Applescript Editor, Script Debugger, or Smile you need to exclude the app from the idList:

set idList to bundle identifier of processes whose visible is true and name is not "Finder" and name is not "Applescript Editor"

It appears to be desirable to keep the Finder from quitting, and timing seems to be an issue.

------------------------------------------------------------------------------------------------
try

  

  tell application "System Events"
    set visible of processes to true
    delay 0.5
    set idList to bundle identifier of processes whose visible is true and name is not "Finder"
  end tell

  

  repeat with i in idList
    tell application id (get contents of i)
      delay 0.1
      quit without saving
    end tell
  end repeat

  

on error e number n
  set e to "Error: " & e & return & return & "Error Number: " & n
  beep
  tell me to set dDlg to display dialog e buttons {"Cancel", "Copy", "OK"} default button "OK"
  if button returned of dDlg = "Copy" then set the clipboard to e
end try
------------------------------------------------------------------------------------------------

A little more fiddling:

------------------------------------------------------------------------------------------------
tell application "System Events"
  set visible of processes to true
  delay 0.5
  set procList to name of processes whose visible is true and name is not "Finder"
end tell
set AppleScript's text item delimiters to "|"
set procList to "\"" & (procList as text) & "\""
set pidList to do shell script "ps auxc | egrep -i " & procList & " | awk '{ print $2}' | tr '\\n' ' '"
set cmd to "kill -15 " & pidList
do shell script cmd
------------------------------------------------------------------------------------------------

A little more fiddling:

(This one takes Mountain Lion for pgrep.)

------------------------------------------------------------------------------------------------
tell application "System Events"
  set visible of processes to true
  delay 0.5
  set procList to name of processes whose visible is true and name is not "Finder"
end tell
set AppleScript's text item delimiters to "|"
set procList to "\"" & (procList as text) & "\""

# See what you're going to kill (comment-out):
set pidList to do shell script "pgrep -ifl -d'|' " & procList & " | sed -e 's:\\|$::' | awk '{ gsub(/\\|/, \"\\n\"); print }'"

# Uncomment to kill apps:
# set pidList to do shell script "pgrep -if -d'|' " & procList & " | sed -e 's:\\|$::'"
# set cmd to "kill " & pidList
# do shell script cmd

------------------------------------------------------------------------------------------------

The final result:

(Takes Mountain Lion for pkill.)

------------------------------------------------------------------------------------------------
tell application "System Events"
  set visible of processes to true
  delay 0.5
  set procList to name of processes whose visible is true and name is not "Finder"
end tell
set AppleScript's text item delimiters to "|"
set procList to "\"" & (procList as text) & "\""
do shell script "pkill -if " & procList
------------------------------------------------------------------------------------------------

I've tried this with my normally running applications ("Terminal|BBEdit|Mail|Script Debugger|Safari") and a few more.

So far it works like a champ.

--
Best Regards,
Chris

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: List of open applications
      • From: "koenig.yvan" <email@hidden>
References: 
 >List of open applications (From: "koenig.yvan" <email@hidden>)
 >Re: List of open applications (From: Axel Luttgens <email@hidden>)
 >Re: List of open applications (From: "koenig.yvan" <email@hidden>)
 >Re: List of open applications (From: Axel Luttgens <email@hidden>)
 >Re: List of open applications (From: "koenig.yvan" <email@hidden>)
 >Re: List of open applications (From: Christopher Stone <email@hidden>)

  • Prev by Date: Re: List of open applications
  • Next by Date: Re: List of open applications
  • Previous by thread: Re: List of open applications
  • Next by thread: Re: List of open applications
  • Index(es):
    • Date
    • Thread