• 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: Safari
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Safari


  • Subject: Re: Safari
  • From: Alex Zavatone <email@hidden>
  • Date: Wed, 03 Apr 2013 12:35:13 -0400

I'm looking into Shane Stanley's ASOC products as a way to create or detect any application state change from System Events but am hampered by time on this front.

It would be great to have a method where events are generated that can be trapped for "this app came to the foreground" and "this app entered the background" that we could trap in AppleScript.

Using a Safari Extension would probably not work, since according to the Apple docs, they are written in _javascript_ so if I use _javascript_ to turn off _javascript_ in Safari, there is no obvious way to turn it back on.



Included below is my previous code for an AS app that allows you to pause and resume Safari manually based on the PID approach mentioned in my previous email.  It should be just a copy and paste.  Enjoy.

-- Basics for pausing and resuming an application (Safari) ala AppleScript.
-- need to wrap in detectors triggered when the application becomes active and when it moves to the back to auto pause and resume.
-- Alex Zavatone 2012
--

property pSafariPID : 0
property pSafariWebContentPID : 0

on run
main()
end run

on main()
GetSafariPID()
log (pSafariPID)
log (pSafariWebContentPID)


display dialog "Pause or Resume Safari?" buttons {"Pause", "Resume"} ¬
default button 1
copy the result as list to {buttonpressed}


try
if the buttonpressed is "Pause" then
PauseSafari()
else if the buttonpressed is "Resume" then
ResumeSafari()
end if
end try


end main

on GetSafariPID()
set myShellString to "ps -Ac"
-- set myResult to every paragraph of (do shell script myShellString) whose (word 4 is "Safari")
set myResultList to paragraphs of (do shell script myShellString)
-- set myParas to paragraphs of myResult where (word 4 = "Safari")
repeat with myItem in myResultList
set myCondition to (word 4 of myItem = "Safari")
if myCondition then
set pSafariPID to word 1 of myItem
--exit repeat
end if


set myCondition to (word 4 of myItem = "WebProcess")
if myCondition then
set pSafariWebContentPID to word 1 of myItem
--exit repeat
end if
end repeat


--return myPID
end GetSafariPID

on PauseSafari()
set myShellString to "set +o posix; kill -SIGSTOP " & pSafariPID
set myResult to do shell script myShellString


set myShellString to "set +o posix; kill -SIGSTOP " & pSafariWebContentPID
do shell script myShellString
end PauseSafari

on ResumeSafari()
set myShellString to "set +o posix; kill -SIGSTOP " & pSafariPID
do shell script myShellString
set myShellString to "set +o posix; kill -SIGSTOP " & pSafariWebContentPID
do shell script myShellString
end ResumeSafari



On Apr 3, 2013, at 12:21 PM, sphilip wrote:

Well, I for one am certainly interested in the problem about Safari and its solution.

Alas, I've no idea as to the answer, but I think its a valid question and I hope the list members can help shed some light on it.


Best

Phil
http://applehelpwriter.com


 _______________________________________________
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

References: 
 >Safari (From: Alex Zavatone <email@hidden>)
 >Re: Safari (From: Alex Zavatone <email@hidden>)

  • Prev by Date: Re: Safari
  • Next by Date: Re: Refresh Finder view?
  • Previous by thread: Re: Safari
  • Next by thread: Re: Safari
  • Index(es):
    • Date
    • Thread