Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I know this is probably possible, and probably easy for someone who knows what they're doing, but I apologize in advance for how little I know.

I'm essentially looking for some sort of code (script? again, I don't know) that will write either the page names and/or full URLs for every visited website (even with private browsing enabled) to a "backup" history file that will not be erased or modified through the standard Safari toolbar. Preferably, this would include timestamps, though that's not required.

Alternately, if it's possible/easier to leave the Private Browsing button enabled, but make it so it doesn't actually DO anything, then write/backup changes to the Safari history plist every 60 seconds or so to a "safe" and uneditable location, that would work, as well.

A couple of things I do not want:

  • Instructions on how to enable Parental Controls or remove the private browsing option

  • Directions to a web monitoring or spy software program which must be downloaded and installed onto the computer

  • Instructions on how to log at the router level (not currently possible) or use Open DNS (which shows domains only, but not all webpages at a granular level)

  • Ethical or moral discussion (I know what I'm asking and why I'm asking for it; please trust me on that one)

I know there are monitoring programs that do what I want (and much more, most of which is unnecessary), so I assume it's possible to code something somewhere that will accomplish the same task. I would also need (I'll be honest) some pretty thorough instructions on how/where to enter this code and make it run. I'm willing to pay (if necessary) to hire someone to do this, but without even knowing exactly what I'm asking for, I'm having trouble formulating a job post on any of the hire-a-freelance-coder sites.

Any help/guidance/assistance/clarification/etc. would be appreciated.

share|improve this question
    
Ethical or moral discussion (I know what I'm asking and why I'm asking for it; please trust me on that one) I'm not going to start the discussion, but without it, you can expect a fair number of people who could help choose not to. Just sayin'.... –  Excellll Aug 9 '13 at 18:44
    
I understand, but I've done a ton of research into this over the past few weeks, and always see the threads hijacked in such a way that the OPs question never gets answered, and nothing ever gets accomplished. Hopefully someone who reads this will understand that every situation is unique and the superfluous commentary is just that. –  pinkheels81 Aug 9 '13 at 19:48
    
<del>Another approach would be to run a proxy server on your machine, and it could intercept all HTTP requests for logging.</del> Nevermind. Just noticed your "do not want" #2. –  Kent Aug 14 '13 at 5:24
add comment

1 Answer

Save a script like this somewhere in the default .scpt format in AppleScript Editor:

repeat
    try
        tell application "System Events"
            if name of (process 1 where frontmost is true) is not "Safari" then error
        end tell
        tell document 1 of application "Safari"
            set u to URL
            set n to name
        end tell
        do shell script "f=/path/to/log_file
u=" & quoted form of u & "
n=" & quoted form of n & "
[[ $(tail -n1 $f | cut -d' ' -f2) = $u ]] && exit
printf '%s\\n' \"$(date +%FT%H:%M) $u $n\" >> $f"
    end try
    delay 10
end repeat

The script is only run every 10 seconds, so it will probably miss some pages. You can reduce the delay if you want though.

You can start the script at login and relaunch it if it exits by saving a property list like this as ~/Library/LaunchAgents/some_label.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>EnableGlobbing</key>
  <true/>
  <key>Label</key>
  <string>some_label</string>
  <key>ProgramArguments</key>
  <array>
    <string>osascript</string>
    <string>/path/to/script.scpt</string>
  </array>
  <key>RunAtLoad</key>
  <true/>
  <key>KeepAlive</key>
  <true/>
</dict>
</plist>

Then load the plist by running launchctl load ~/Library/LaunchAgents/some_label.plist or by logging out and back in.

share|improve this answer
    
Thank you. So much. That is pretty much exactly what I needed. I had a feeling I was looking for something applescript, and knew it had the ability to do what I wanted it to do on a one-off basis, but didn't know how to accomplish the task without invoking some sort of hotkey or button. Thank you again. –  pinkheels81 Aug 12 '13 at 16:41
    
I've read through this many times over the past couple of days (before taking the leap) and just realized I may not have this all down. In this part: do shell script "f=/path/to/inconspicuous_file, is the inconspicuous file one I create new right now? Meaning...it doesn't currently exist (or is it referring to something else)? If so, would you recommend a .txt? Or do I not need to create it first because it will create itself –  pinkheels81 Aug 13 '13 at 20:41
    
You don't have to create the file. It is created by the script, and the filename extension doesn't matter. –  Lauri Ranta Aug 13 '13 at 21:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.