|
|
#1 |
|
Apple script & safari tabs
Hello everyone,
I'm very new to applescript and I'm trying to write the url of every tab I've on safari and their duration (starts when I open the tab end when the tab is closed) to a txt file. The problem is I don't even know how to do a "print" or "trace" to see if I'm receiving any values... Can anyone help me out ?? a little script would be great ... Thanks alot |
|
|
|
0
|
|
|
#2 |
|
In script editor, the last variable or value returned is listed after the script is run. If you need more than that, just do a
Code:
display dialog x or you declare an array (called a list in applescript) and assign each variable to a key of that array and then call it at the very end of your script. doing so would list all values in the bottom half of the script editor window after the script has run.
__________________
MBP i7 | iPhone 4 | iPad
|
|
|
|
0
|
|
|
#3 | |
|
Quote:
Code:
#!/usr/bin/python
from os.path import expanduser
from datetime import datetime
from time import sleep
from appscript import *
pth = expanduser('~/watched tabs.txt')
openurls = {}
while 1:
foundurls = set(openurls.keys())
for urls in app('safari').windows.tabs.URL():
for url in urls:
if url in openurls:
foundurls.remove(url)
elif url != k.missing_value:
openurls[url] = datetime.now()
f = open(pth, 'a')
for url in foundurls:
f.write('%s\t%s\n' % (datetime.now() - openurls.pop(url), url.encode('utf8')))
f.close()
sleep(1)
__________________
Learn AppleScript, 3rd edition, Sanderson & Rosenthal: http://apress.com/book/view/9781430223610 Control AppleScriptable applications from Python, Ruby and ObjC: http://appscript.sourceforge.net |
||
|
|
0
|
|
|
#4 |
|
hey man,
thank you very much for this piece of code this looks great but I've one more question I never used python I dont even know how to compile it ... if I make a .py file and than use the Build Applet thing in osx should this work? is it really that simple python & mac ![]() This made me think about starting to learn python .. Thanks again PS:I tried creating a app with Build Applet and saw that it's not working.. I wasnt counting on it anyways
|
|
|
|
0
|
|
|
#5 |
|
Hello,
The appscrpt lib was missing on my system , I just installed appscrpt lib and now it works !! thank you for this great script ... |
|
|
|
0
|
![]() |
|
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| thread | Thread Starter | Forum | Replies | Last Post |
| Lion. Safari not quitting, and closing tabs. | donfishinghocke | Mac OS X 10.7 Lion | 7 | Jun 27, 2012 02:55 AM |
| apple script for safari | Dr Kevorkian94 | Mac Programming | 2 | Aug 23, 2011 07:21 PM |
| Safari 5.1 Tab Behaviour | Jas0n | Mac Applications and Mac App Store | 13 | Jul 27, 2011 05:35 AM |
| Safari tab issue, safari crashing and macbook heating up - help | Pipsicle10 | Mac Applications and Mac App Store | 1 | Nov 4, 2010 05:45 PM |
| Apple Script & Text | i.shaun | Mac Programming | 0 | May 11, 2008 04:02 PM |
All times are GMT -5. The time now is 06:00 PM.







Linear Mode

