Jump to content
jshin593

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

Share this post


Link to post

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.

Share this post


Link to post

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

Share this post


Link to post

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

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...