Jump to content

Basic Question: How to Open a New Chrome Window


Recommended Posts

Hi, 

 

It seems like a basic thing, but, since I have no basis in even basic programming, I came to get some help here. 

 

Question

What would be the script to open up a new chrome window (instead of the pre-set 'Launch Apps/Files' action in Alfred, which would toggle an already opened chrome window, if there is one)? 

 

 

Thanks in advance for those who can help.  :)

Link to comment

In the workflow, set it to Bash and have the command be: 

osascript activate.scpt "<INSERT URL HERE>"

Create a file called "activate.scpt" and place it in the root of the workflow directory.

on run argv
	set theUrl to item 1 of argv
	tell application "Google Chrome"
		
		if (count every window) = 0 then
			make new window
		end if
		
		set found to false
		set theTabIndex to -1
		set theWindowIndex to 0
		repeat with theWindow in every window
			set theWindowIndex to theWindowIndex + 1
			set theTabIndex to 0
			repeat with theTab in every tab of theWindow
				set theTabIndex to theTabIndex + 1
				if the URL of theTab contains theUrl then
					set found to true
					exit repeat
				end if
			end repeat
			
			if found then
				exit repeat
			end if
		end repeat
		
		if found then
			set theWindow's active tab index to theTabIndex
			activate window theWindow
			tell application "System Events" to tell process "Google Chrome"
				delay 1
				perform action "AXRaise" of window theWindowIndex
			end tell
			set the index of theWindow to 1
		else
			tell window 1 to make new tab with properties {URL:theUrl}
		end if
	end tell
end run

This gets you there. It sometimes doesn't bring up the main window if multiple ones are there. I just haven't had time to debug it.

Link to comment
  • 2 weeks later...

The other day, I've asked the same question and Shawn has made a reply for me thankfully, but, I couldn't quite get it. 

 

The usual actions that I wish to make into workflow are 1) Move a mouse cursor to the Chrome icon in the Dock, 2) Right click the Chrome icon, and 3) Select the New Window menu. 

 

Does anyone have idea on how to make the above actions into a single workflow and a script? I would really appreciate your help. 

 

Best regards,

DJ

Edited by jshin593
Link to comment

The other day, I've asked the same question and Shawn has made a reply for me thankfully, but, I couldn't quite get it. 

 

 

Hi there, I've merged your question back with your original thread, as there's no benefit in starting a whole new thread, which clutters up the forum.  If you're having issues with Shawn's advice, ask your further questions here to get help :)

 

Cheers,

Vero

Link to comment

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...