Open a URL in a private/incognito window

8,421 views
Skip to first unread message

Jonathan Levi

unread,
Dec 29, 2015, 10:25:27 PM12/29/15
to Quicksilver
Hi all
I am often testing web pages to see what a not-logged-in user would see. I find that the fastest way to do this is to open a new Private window in Safari (or incognito window in Chrome) and paste the URL there. 

It would be so much faster if we could either add an action "Open in Private Window" or "Open With..." (tab) "Safari Private Window"

Then, from there, I could pretty easily make a custom trigger so that it took my clipboard contents and automatically opened in a private url. Something like Option + Command + Control + N.

Any ideas how I can do this most easily?

Thanks all
JL

Dave Land

unread,
Dec 30, 2015, 12:47:40 AM12/30/15
to blacktree-...@googlegroups.com
Hi, Jonathan,

This little snippet of AppleScript does the trick:

on open location theURL
tell application "/Applications/Google Chrome.app"
make new window with properties {mode:"incognito"}
activate
set URL of active tab of first window to theURL
end tell
end open location

I'm not sure if the "open location theURL" is useful to you in exactly that form,
because it comes from a script application that I set as my default browser so
that I can open links from other apps in a new window, including an incognito
window, if desired, but it shows where theURL comes from in the "set URL…"
line.

Hope this helps.

Dave

Dave Land
---------------------------------
User Experience Director
LiveWorld

Twitter   @dland

Follow Us   Facebook | Twitter | LinkedIn

--
You received this message because you are subscribed to the Google Groups "Quicksilver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blacktree-quicks...@googlegroups.com.
To post to this group, send email to blacktree-...@googlegroups.com.
Visit this group at https://groups.google.com/group/blacktree-quicksilver.
For more options, visit https://groups.google.com/d/optout.

1.61803

unread,
Dec 31, 2015, 10:44:41 AM12/31/15
to Quicksilver
This is a short applescript that you can put in ~/Library/Application Support/Quicksilver/Actions/.

using terms from application "Quicksilver"
 on process text theURL
 tell application
"Google Chrome"

 make
new window with properties {mode:"incognito"}
 activate
 
set URL of active tab of first window to theURL
 
end
tell
 
end process text
 on
get direct types
 
return {"NSStringPboardType", "Apple URL pasteboard type"}
 
end get direct types
end using terms from


This is a longer applescript that also let's you open multiple URLs separated by commas, use web search strings (see comment in script), close the default window when launching Chrome and switch to either full screen or presentation mode.

using terms from application "Quicksilver"
 
 on process text theURLs
 
 
if not running of application "Google Chrome" then ¬
 tell application
"Google Chrome" to close front window
 
 
if theURLs contains "," then ¬
 
set theURLs to theURLsToCSV(theURLs)
 
if (count of theURLs) is 2 and item 1 of theURLs contains "***" then ¬
 
set theURLs to theURLsToWebSearch(theURLs)
 
 repeat
with theURL in theURLs as list
 
if theURL does not start with "http" then set theURL to "http://" & theURL
 tell application
"Google Chrome"
 activate
 
if not ((some window whose mode is "incognito") exists) then

 make
new window with properties {mode:"incognito"}

 
set URL of active tab of first window to theURL
 
else
 make
new tab at (front window whose mode is "incognito") with properties {URL:theURL}
 
end if
 
end tell
 
end repeat
 
 
-- Full Screen Mode
 tell application
"System Events"
 
if not (value of attribute "AXFullScreen" of front window of process "Google Chrome") then ¬
 keystroke
"f" using {command down, control down}
 
end tell
 
-- Presentation Mode
 
(** tell application "Google Chrome" to tell front window
 
if not presenting then enter presentation mode
 
end tell **)
 
 
end process text
 
 on
get direct types
 
return {"NSStringPboardType", "Apple URL pasteboard type"}
 
end get direct types
 
end using terms from


on theURLsToCSV
(theURLs)
 
-- for multiple values use comma-separated text
 
-- comma trick doesn't work with text nor URLs #1727
 set ASTID to AppleScript'
s text item delimiters
 
set AppleScript's text item delimiters to ","
 set theCSURLs to text items of theURLs
 set AppleScript'
s text item delimiters to ASTID
 
return theCSURLs
end theURLsToCSV


on theURLsToWebSearch
(theURLsAsWebSearch)
 
-- usage: select QS Web Search, change to text mode, add search terms after a comma
 
-- example: http://www.google.com/search?hl=en&q=***,søren kierkegaard
 
set theSearchTerms to urlEncode(item 2 of theURLsAsWebSearch)
 
set QSWebSearchURL to item 1 of theURLsAsWebSearch
 
set theWebSearchURL to findReplace("***", theSearchTerms, QSWebSearchURL)
 
return theWebSearchURL
end theURLsToWebSearch


on urlEncode
(theSearchTerms)
 
return do shell script "php -r 'echo urlencode(\"" & theSearchTerms & "\");'"
end urlEncode


on findReplace
(findText, replaceText, sourceText)
 
set ASTID to AppleScript's text item delimiters
 set AppleScript'
s text item delimiters to findText
 
set sourceText to text items of sourceText
 
set AppleScript's text item delimiters to replaceText
 set sourceText to sourceText as text
 set AppleScript'
s text item delimiters to ASTID
 
return sourceText
end findReplace

I tested with most cases (full screen, presentation, normal, incognito, 1+ tabs) at the same time. Let me know how it works.

Rob McBroom

unread,
Jan 4, 2016, 11:58:19 AM1/4/16
to Quicksilver
On 28 Dec 2015, at 6:52, Jonathan Levi wrote:

> It would be so much faster if we could either add an action "Open in
> Private Window" or "Open With..." (tab) "Safari Private Window"

The existing actions (Open URL and Open URL in Background) just hand the
URL to the OS and your preferences (default browser, tab vs. window,
etc.) take over from there.

Since the private modes of various browsers were all developed
independently, I don’t think there’s any standard way to tell the OS
to open a private window.

It should be possible to add an action to each browser’s Quicksilver
plug-in to handle this, though.

Until then, you’ll need to create an AppleScript action as described
by others.

> Then, from there, I could pretty easily make a custom trigger so that
> it
> took my clipboard contents and automatically opened in a private url.
> Something like Option + Command + Control + N.

Better yet, skip the steps of selecting and copying the URL. Just use
the “Current Web Page” proxy.

--
Rob McBroom
http://www.skurfer.com/

Jonathan Levi

unread,
Jan 10, 2016, 3:38:50 AM1/10/16
to Quicksilver
By the way, I made .scpt files in the appropriate directory for each of these, but I can't get either of them to work.

Jonathan Levi

unread,
Jan 10, 2016, 3:38:50 AM1/10/16
to Quicksilver
This is awesome. Thanks to those of you who replied.

Any ideas how to do it with Safari? 
To unsubscribe from this group and stop receiving emails from it, send an email to blacktree-quicksilver+unsub...@googlegroups.com.

1.61803

unread,
Jan 10, 2016, 7:47:06 AM1/10/16
to Quicksilver
On Sunday, January 10, 2016 at 9:38:50 AM UTC+1, Jonathan Levi wrote:
By the way, I made .scpt files in the appropriate directory for each of these, but I can't get either of them to work.

Both actions I tested in QS 1.2.0.

How about you give a more detailed description of your problem?

E.g., do the scripts compile in AppleScript Editor, do the actions show in the second pane, do you see any errors in Console?


You can use Proxy Objects from QS's catalogue to open the current URL in another browser.

Current Web Page (Safari) ⇥ Open With… ⇥ Your Browser

As explained in this thread before, for private modes you'll rather have to resort to some applescript.

I use the longer script I posted in the second pane in a trigger scoped to Safari.

Current Web Page (Safari) ⇥ Incognito Window

Jonathan Levi

unread,
Jan 11, 2016, 2:21:20 AM1/11/16
to Quicksilver
Hey, thanks for the fast reply.

I'm on QS 1.3.4, and on Yosemite, so I don't have AppleScript Editor, I have "Script Editor"

Got it working in Chrome!!! Awesome, thank you. 

I guess this works and fulfills my needs. I don't understand really how to modify your code to make it open a private Safari window. I read your reply about 10x, but I'm not sure if we're talking about the same thing. It sounds like you're offering a way to move a page from Safari to a chrome incognito window. I'm looking for a way to launch a private safari window with whatever input is in the left pane on quicksilver.

If you're feeling generous, I'd love a way to do it, but if not, you've already helped me a great deal and I can use the script you gave me to do what I want (though it has a lot more features I don't understand yet)

Thanks
JL

Jon Stovell

unread,
Jan 11, 2016, 4:51:59 AM1/11/16
to blacktree-...@googlegroups.com
Unfortunately, Safari does not offer programmatic access to its privacy mode. But you can accomplish the task easily enough using this:

using terms from application "Quicksilver"
on process text theURL
tell application "Safari"
set window_ids to id of every window
activate
end tell
tell application "System Events" to keystroke "N" using {command down, shift down}
tell application "Safari"
repeat 10 times
if id of front window is not in window_ids then
set the URL of its front window's current tab to theURL
exit repeat
end if
delay 0.1
end repeat
end tell
end process text
on get direct types
return {"NSStringPboardType", "Apple URL pasteboard type"}
end get direct types
end using terms from


Just save it ~/Library/Application Support/Quicksilver/Actions with a name like "Open in Private Safari Window" and relaunch QS.

Jonathan A. Levi

unread,
Jan 11, 2016, 6:33:53 AM1/11/16
to blacktree-...@googlegroups.com
Afraid that one doesn’t work. Had to change “shift” to “option” for my particular setup, but still, doesn’t open any window. Oh well. 

--
Jonathan Levi
Entrepreneur & Eclectic
http://jle.vi
P.S. If I could ask you to do me just ONE favor today, it would be to check out either my TED talk or my Podcast and share it if you enjoy it! Thanks!

P.P.S. My goal is to drastically reduce my use of email in 2016. I hope you’ll join me, and together, we can all be our most productive, least distracted selves!

--
You received this message because you are subscribed to a topic in the Google Groups "Quicksilver" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/blacktree-quicksilver/pb11EIZALYg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to blacktree-quicks...@googlegroups.com.

1.61803

unread,
Jan 11, 2016, 10:18:24 AM1/11/16
to Quicksilver
On Monday, January 11, 2016 at 8:21:20 AM UTC+1, Jonathan Levi wrote:
If you're feeling generous, I'd love a way to do it, but if not, you've already helped me a great deal and I can use the script you gave me to do what I want (though it has a lot more features I don't understand yet)

I'm feeling lack of time actually, but I'll give it a shot when I can.

Two things first — can you tell if, when you click on Safari menu bar item, you see an item named Private Browsing, and, if you enable it, does it show a check mark?

And, when enabled, is it so for all tabs and windows or just for the one you were at when changing mode?


In case you use Tor Browser (which actually uses Firefox) you could also use this other applescript the same way.

1.61803

unread,
Jan 12, 2016, 12:35:33 PM1/12/16
to Quicksilver
On Monday, January 11, 2016 at 8:21:20 AM UTC+1, Jonathan Levi wrote:
I'm on QS 1.3.4, and on Yosemite

After seeing your promo TED talk, I guessed you might have already learnt AppleScript and wrote it yourself overnight :D

Else, here's an ugly GUI applescript, that is, it does the clicking, etc for the user, and since the GUI structure changes between versions, it might not even work for you. Access for assistive devices, or whatever is called in your system, must me enabled in System Preferences for it to function.

The script itself sucks with all the nesting, etc, but it takes into account if a shortcut has been assigned to "Private Browsing…", in which case you might end up with two items, one with ellipsis, one without.

It works with web searches (see comment in script) and full screen (uncomment ⌃⌘F tell block if unneeded).

Tested in Safari 6. YMWV.

using terms from application "Quicksilver"

 
 on process text theURLs
 
 
if theURLs contains "," then ¬

 
set theURLs to theURLsToCSV(theURLs)
 
if (count of theURLs) is 2 and item 1 of theURLs contains "***" then ¬
 
set theURLs to theURLsToWebSearch(theURLs)

 
 tell application
"Safari"
 activate
 
if running then ¬
 tell application
"System Events" to tell process "Safari" to ¬
 tell menu bar
1 to tell menu bar item "Safari" to tell menu 1
 
try
 tell menu item
"Private Browsing…"
 
try
 
set checkMark to value of attribute "AXMenuItemMarkChar"
 log checkMark
-- errors when undefined
 on error
 click
 tell application
"System Events" to tell process "Safari" to tell first window to click button "OK"
 
end try
 
end tell
 
end try
 
 tell application
"Safari"
 activate
 
if not (exists (every window whose id 1)) then make new document
 repeat
with theURL in theURLs as list
 
if theURL does not start with "http" then set theURL to "http://" & theURL
 tell first window to make
new tab with properties {URL:theURL}
 
end repeat
 tell first window to
set current tab to last tab
 
end tell
 
end tell
 
end tell
 
 tell application
"System Events"
 
if not (value of attribute "AXFullScreen" of front window of process "Safari") then ¬

 keystroke
"f" using {command down, control down}
 
end
tell
 
 
end process text
 
 on
get direct types
 
return {"NSStringPboardType", "Apple URL pasteboard type"}

Jon Stovell

unread,
Jan 12, 2016, 3:17:15 PM1/12/16
to Quicksilver
I forgot to mention that you need to enable access for assistive devices. On older versions of OS X this is a simple check box in the Accessibility pane in System Preferences. On newer versions, you'll need to go to the Security & Privacy pane, select the Privacy tab, select the Accessibility item in the left sidebar, and add Quicksilver to the list of applications that are allowed to control your computer.

1.61803

unread,
Jan 12, 2016, 3:52:00 PM1/12/16
to Quicksilver
On Tuesday, January 12, 2016 at 9:17:15 PM UTC+1, Jon Stovell wrote:
I forgot to mention that you need to enable access for assistive devices.

And the version you tested on. ⇧⌘N leaves you with a new bookmarks folder in Safari 6. I suppose "Private Browsing…" is still in the same place in newer versions? 

Jonathan A. Levi

unread,
Jan 13, 2016, 1:11:45 AM1/13/16
to blacktree-...@googlegroups.com
Wow, thanks for all your hard work.
I’m on a version where I don’t have “Private Browsing…” but rather “New Private Window”

I tried to change that in your Applescript but it didn’t work.

Let me know if you’d like a copy of my book, as a thank you :)

--
Jonathan Levi
Entrepreneur & Eclectic
http://jle.vi
P.S. If I could ask you to do me just ONE favor today, it would be to check out either my TED talk or my Podcast and share it if you enjoy it! Thanks!

P.P.S. My goal is to drastically reduce my use of email in 2016. I hope you’ll join me, and together, we can all be our most productive, least distracted selves!

1.61803

unread,
Jan 13, 2016, 8:51:36 AM1/13/16
to Quicksilver
On Wednesday, January 13, 2016 at 7:11:45 AM UTC+1, Jonathan Levi wrote:
Wow, thanks for all your hard work.
I’m on a version where I don’t have “Private Browsing…” but rather “New Private Window”
I tried to change that in your Applescript but it didn’t work.
Let me know if you’d like a copy of my book, as a thank you :)

I checked some images in Google and of course it won't work, the menu item "New Private Window" is under menu bar item "File".

Use Jon's script after enabling Access for assistive devices in System Preferences.

Both could be merged with Safari version checking, but I don't have the time, nor need for that.

Your book about speed reading, right? Nice, send me the link. I hope I can only say better than Woody.

"I took a speed-reading course and read War and Peace in twenty minutes. It involves Russia." 

Jonathan A. Levi

unread,
Jan 17, 2016, 2:17:26 AM1/17/16
to blacktree-...@googlegroups.com
Assistive devices was enabled… not sure what’s going on or what I need to do.

Will email you a copy of the book 

--
Jonathan Levi
Life Enthusiast
http://jle.vi
P.S. If I could ask you to do me just ONE favor today, it would be to check out either my TED talk or my Podcast and share it if you enjoy it! Thanks!

P.P.S. My goal is to drastically reduce my use of email in 2016. I hope you’ll join me, and together, we can all be our most productive, least distracted selves!
Reply all
Reply to author
Forward
0 new messages