forked from DonovanChan/fmfunctions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppleScriptOpenInSafari.calc
52 lines (47 loc) · 1.52 KB
/
AppleScriptOpenInSafari.calc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"set theURL to \"" & url & "\"¶
tell application \"Safari\"¶
activate¶
-- Ensure we're not working in the Downloads window¶
try¶
set frontName to name of front window¶
if frontName is \"Downloads\" then 1/0¶
if frontName begins with \"Source\" then 1/0¶
on error¶
make new document with properties {URL:\"\"}¶
end try¶
end tell¶
tell front window of application \"Safari\"¶
try¶
-- If in blank tab, use that one¶
set myURL to URL of front document¶
try¶
set test to myURL¶
set newTab to make new tab¶
on error¶
set newTab to current tab¶
end try¶
set the URL of newTab to theURL¶
set the current tab to newTab¶
set miniaturized to false¶
on error errText number errNum¶
set errMessage to \"Error \" & errNum & \": \" & errText¶
display alert errMessage & errText giving up after 60¶
-- Write error to text file (for debugging)¶
--my updateLog(errMessage,\"~/Desktop/error_log.txt\")¶
end try¶
end tell¶
¶
-- HANDLER: Appends new timestamped line to log file¶
-- Alternative file name or location must be modified in the code¶
on updateLog(logEntry)¶
do shell script \"TEXT=$(echo \" & quoted form of logEntry & \" ); echo \\\"`date '+%Y.%m.%d %H:%M:%S'`\t$TEXT\\\" >> ~/Desktop/error_log.txt\"¶
end updateLog"
/* —————————————————————————————— //
NAME:
AppleScriptOpenInSafari ( url )
PURPOSE:
Opens URL in new tab in Safari
EXAMPLES:
HISTORY:
Created: 2011-Aug-18 10h59 PST — Donovan A. Chandler
*/