Jump to content

How to open current url in Safari as incognito in Google Chrome?


Recommended Posts

Posted

Question: How to get the frontmost url from Safari and open it in Google Chrome Incognito?

 

So far I was able to get the name of frontmost url. I have also seen another workflow to open in chrome incognito. But, I was struggling to combine two.

I would truly appreciate if somebody jumps in and give me suggestions.

 

I am looking for AppleScript that will do the work, if there is AppleScript I will be able to create new Alfred Workflow and use it there.

 

 

Some references are included below:

 

 

Posted
const chrome = Application('Google Chrome')
const safari_url = Application('Safari').documents[0].url()
chrome.Window({ mode: 'incognito' }).make()
chrome.windows[0].activeTab.url = safari_url

 

Posted (edited)

@vitor  The code suggested is much more concise,  I also got another AppleScript solution from stack overflow:

The problem is solved. You can close the topic.

 

if running of application "Safari" then
    
    tell application "Safari"
        if the URL of ¬
            the current tab of ¬
                the front window ¬
                    does not contain missing value then
            set theURL to ¬
                the URL of ¬
                    the current tab of ¬
                        the front window
        else
            return
        end if
    end tell
    
    if running of application "Google Chrome" then
        
        tell application "Google Chrome"
            set incognitoWindowIDs to ¬
                the id of every window ¬
                    whose mode is "incognito"
            if incognitoWindowIDs is {} then
                activate
                my openNewIncognitoWindow()
                delay 1
                set URL of ¬
                    the active tab of ¬
                        the front window to theURL
            else
                make new tab at end of ¬
                    window id (first item of incognitoWindowIDs) ¬
                        with properties {URL:theURL}
            end if
        end tell
    else
        tell application "Google Chrome"
            activate
            delay 1
            my openNewIncognitoWindow()
            delay 1
            set URL of ¬
                the active tab of ¬
                    the front window to theURL
        end tell
    end if
    
end if

on openNewIncognitoWindow()
    tell application "System Events" to ¬
        keystroke "n" using ¬
            {shift down, command down}
end openNewIncognitoWindow

 

Edited by Bhishan
Posted

I recommend against that code as is. It is unnecessarily large (though it has some extra checks, but most are not needed) and it relies on waiting around and simulating keystrokes, which is in general a bad idea and more prone to errors.

Posted

hi @vitor how exactly do I create the workflow for the code you shared above? This is what I've tried but it doesn't work. I also changed it a bit. I'm trying to get the frontmost url from Chrome Non-Incognito and open it in  Chrome's Incognito? 

CleanShot 2021-03-27 at 20.32.55@2x.png

Posted
2 hours ago, leonseled said:

This is what I've tried but it doesn't work.

 

We can't help you with a description like "it doesn't work". When you're having an issue with a workflow, please upload it somewhere (Dropbox?) and post a link, so we can have a look for ourselves.

Posted

 

On 3/27/2021 at 11:12 PM, deanishe said:

 

We can't help you with a description like "it doesn't work". When you're having an issue with a workflow, please upload it somewhere (Dropbox?) and post a link, so we can have a look for ourselves.

Apologies. On hindsight I probably should have attached the workflow and error. Thought it was just a syntax issue so screenshot of how I wrote it would've sufficed.

 

On 3/27/2021 at 11:20 PM, vitor said:

 

Try IncognitoClone, which already does that.

 

Awesome this works great. This didn't pop up in my forum search results for "chrome incognito workflow". Thanks for the help and workflow, Vitor! 

Posted (edited)
2 hours ago, leonseled said:

I probably should have attached the workflow and error

 

Unfortunately, you can't attach workflow files to forum posts (only images).

 

2 hours ago, leonseled said:

Thought it was just a syntax issue

 

Doesn't really make any difference: brains aren't very good at parsing code.

 

Also, if you do have a syntax error, there's usually an error message in Alfred's debugger telling you precisely where it is.

Edited by deanishe
Posted
2 hours ago, leonseled said:

Thought it was just a syntax issue so screenshot of how I wrote it would've sufficed.

 

In this case yes, but only because I wrote the code you copied and I’ve put a lot of work into understanding these AppleScript browser differences. The issue is that Chrome doesn’t understand documents[0]; it would have needed to be windows[0].activeTab. But even I had to look that up from my notes, because Safari has the similar windows[0].currentTab and those aren’t interchangeable.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...