• 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: Script to pause/suspend Safari when in the background and resume when in foreground
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Script to pause/suspend Safari when in the background and resume when in foreground


  • Subject: Re: Script to pause/suspend Safari when in the background and resume when in foreground
  • From: Alex Zavatone <email@hidden>
  • Date: Wed, 03 Apr 2013 15:44:01 -0400

Here's a little test script you can paste and run.  The log returns true whether Safari is in the foreground or the background on my system. if you comment out the ≠, the PID of the Safari process and the elapsed CPU time is still displayed.

on run {}
main()
end run

on main()
repeat while true
set myResult to (do shell script "ps -Ac | sed -En '/Safari$/p'") ≠ ""
log (myResult)
if (do shell script "ps -Ac | sed -En '/Safari$/p'") ≠ "" then
tell application "Safari"
if not frontmost then
# Kill _javascript_
end if
end tell
end if
DoDelay(1)
end repeat
end main

on DoDelay(timeInSeconds)
-- We do this shell command because on some versions of the Mac OS, if this is running as a compiled app,
-- using the delay command will use up 100% of an entire core until the delay is finished.
-- Therefore, we have to wrap a call to a shell script which is synchronous and will not do this.
-- Lame.


set myShellScript to "sleep " & timeInSeconds
do shell script myShellScript
end DoDelay



On Apr 3, 2013, at 2:28 PM, Christopher Stone wrote:

if (do shell script "ps -Ac | sed -En '/Safari$/p'") ≠ "" then
  tell application "Safari"
    if not frontmost then
      # Kill _javascript_
    end if
  end tell
end if

 _______________________________________________
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: Script to pause/suspend Safari when in the background and resume when in foreground
      • From: Christopher Stone <email@hidden>
References: 
 >Safari (From: Alex Zavatone <email@hidden>)
 >Re: Safari (From: Luther Fuller <email@hidden>)
 >Re: Safari (From: 2551phil <email@hidden>)
 >Script to pause/suspend Safari when in the background and resume when in foreground (From: Alex Zavatone <email@hidden>)
 >Re: Script to pause/suspend Safari when in the background and resume when in foreground (From: Christopher Stone <email@hidden>)

  • Prev by Date: Re: Safari
  • Next by Date: Re: Passing InDesign variables from one script to an other
  • Previous by thread: Re: Script to pause/suspend Safari when in the background and resume when in foreground
  • Next by thread: Re: Script to pause/suspend Safari when in the background and resume when in foreground
  • Index(es):
    • Date
    • Thread