views:

25

answers:

2

Hi,

Just wondering if there's a way to keep track of what website the user is browsing to via Cocoa or Webkit?

Sort of like the TrackTime.app?

Thanks

A: 

Well this has nothing to do with WebKit. You'd have to use AppleScript or similar to track what Safari's up to. Alternatively, might be able to monitor it's history storage on-disk.

Mike Abdullah
A: 

I'm developing a time tracking app without timers called Lapsus.

Mike is correct - the answer lies in the following AppleScript:

tell application "Safari"
    URL of current tab of window 1
end tell   

I'm doing this right now in my app and it works like a charm.

If you're building a Cocoa app as I am, you can execute this with NSAppleScript, the Scripting Bridge or, more ideally, with the Objective C bindings for AppScript.

I check if window 1 exists first, but if you want to run this script as one, you might want to surround it with a @try @catch block to catch any exceptions NSAppleScript throws.

John Gallagher
Thanks. That's exactly what I needed. Good luck with your app~
Dan