-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathChromeHelper.applescript
More file actions
56 lines (46 loc) · 1.81 KB
/
Copy pathChromeHelper.applescript
File metadata and controls
56 lines (46 loc) · 1.81 KB
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
53
54
55
56
(*
Open in Chrome (Helper app)
by Luke Hagan <lukehagan.com>
created 2012-01-22
released under the MIT license (see LICENSE.md for details)
based on Use AppleScript to open current Safari URL in Google Chrome by TJ Luoma
http://www.tuaw.com/2011/03/14/use-applescript-to-open-current-safari-url-in-google-chrome/
*)
on open location theURL
-- split URL string to remove the chromehelper:// prefix
set theURL to rightString(theURL, "://")
tell application id "com.google.Chrome"
-- open Chrome if it's not open, create a new window if none exists, bring into focus
activate
-- delay to make sure window is open before we start doing anything
delay 0.5
-- if Chrome's active tab is non-blank, create a new tab
-- if a blank tab is active, just use that
-- otherwise, make a new window
-- based on a script by scott.c.jordan
-- http://www.tuaw.com/2011/03/14/use-applescript-to-open-current-safari-url-in-google-chrome/#aolc=A0yOBA
if (count of (every window where visible is true)) is greater than 0 then
if URL of active tab of front window is not "chrome://newtab/" then
tell front window
make new tab
end tell
end if
else
make new window
end if
set URL of active tab of front window to "http://" & theURL
activate
end tell
end open location
-- split theString into two parts based on a delimiter and return the rightmost part
-- note: only works properly if the delimiter appears only once in the string
on rightString(theString, theDelimiter)
-- save current delimiters for later
set currentDelimiters to AppleScript's text item delimiters
-- set new delimiter
set AppleScript's text item delimiters to theDelimiter
-- create an array of items
set array to every text item of theString
-- return the rightmost part of the string
return item 2 of array
end rightString