Jump to content

Possible to distinguish between Chrome OS X; and Chrome Win?


Recommended Posts

Hello all,

 

Downloaded one of those "Open Safari in Chrome" workflows (many thanks to Andrew Curtis-Black), that I use extensively to get around any video-play issues.

 

Now I've hit a bit of an annoyance/1st World Problem. 

I've since started using Parallels to run Windows 7 as a VM, but in the "coherence"(?) mode - i.e., where the Win apps 'open' as OS X apps - as opposed to being 'kept' inside the VM desktop/machine (hope I'm explaining that sensibly).

 

What happens now, is when I run the workflow, the Windows Chrome version is opened, as opposed to the OS X version, and in the case of the former, the script obviously(?) doesn't complete, in order to paste the Safari url across. 

 

After checking the script, I think the 'problem' is that the script says [[tell "Google Chrome"...]] - and since both are 'called'(?) Google Chrome, and are available to be triggered, the wrong one gets opened (mostly - sometimes the OS X version triggers first)...

 

Please understand - I'm not complaining, or being at all critical of someone's work/workflow! It works perfectly, it's me that's introduced the complications!

 

But regardless, is this something that is unavoidable, or could there be a way to use an alternative 'identifier'(??) for Chrome, or something?

I don't know anything about scripting, but know where to go and ask - but figured I would 1st pop something up here, to see if there isn't maybe a simpler solution - or (alternatively), to confirm that nothing can really be done, before I start searching properly... 

 

Many thanks! 

 

 

Link to comment

Hello all,

 

Downloaded one of those "Open Safari in Chrome" workflows (many thanks to Andrew Curtis-Black), that I use extensively to get around any video-play issues.

 

Now I've hit a bit of an annoyance/1st World Problem. 

I've since started using Parallels to run Windows 7 as a VM, but in the "coherence"(?) mode - i.e., where the Win apps 'open' as OS X apps - as opposed to being 'kept' inside the VM desktop/machine (hope I'm explaining that sensibly).

 

What happens now, is when I run the workflow, the Windows Chrome version is opened, as opposed to the OS X version, and in the case of the former, the script obviously(?) doesn't complete, in order to paste the Safari url across. 

 

After checking the script, I think the 'problem' is that the script says [[tell "Google Chrome"...]] - and since both are 'called'(?) Google Chrome, and are available to be triggered, the wrong one gets opened (mostly - sometimes the OS X version triggers first)...

 

Please understand - I'm not complaining, or being at all critical of someone's work/workflow! It works perfectly, it's me that's introduced the complications!

 

But regardless, is this something that is unavoidable, or could there be a way to use an alternative 'identifier'(??) for Chrome, or something?

I don't know anything about scripting, but know where to go and ask - but figured I would 1st pop something up here, to see if there isn't maybe a simpler solution - or (alternatively), to confirm that nothing can really be done, before I start searching properly... 

 

Many thanks! 

 

Could you provide a link to the workflow you're referring to so I can take a look at it?? I would think that the AppleScript wouldn't be an issue because the application has to provide an AppleScript dictionary in order for OS X to call upon it. The Windows applications wouldn't have this obviously as they don't support AppleScript.

Link to comment

Could you provide a link to the workflow you're referring to so I can take a look at it?? I would think that the AppleScript wouldn't be an issue because the application has to provide an AppleScript dictionary in order for OS X to call upon it. The Windows applications wouldn't have this obviously as they don't support AppleScript.

 

Thanks for the help David - here be the link

Link to comment

 

I can't test this, as I don't use Parallels (because I think it's a scummy company), but it might work if you call Chrome via open instead.

 

Replace the Chrome part of the AppleScript with:

do shell script "open -a 'Google Chrome' " & quoted form of currentSafariURL
But if Parallels is dicking about with AppleScript dictionaries/definitions, that likely won't work.
Link to comment

I can't test this, as I don't use Parallels (because I think it's a scummy company), but it might work if you call Chrome via open instead.

Replace the Chrome part of the AppleScript with:

do shell script "open -a 'Google Chrome' " & quoted form of currentSafariURL
But if Parallels is dicking about with AppleScript dictionaries/definitions, that likely won't work.

Many thanks - will give your suggestion a try, and come back with what happens!

Link to comment

No go. Am too stooopid when it comes to scripting - must still learn the ropes.

 

I gather the suggested shell script above, was intended to bypass most (if not all) of the current Chrome applescript - but figure that it would interrupt the latter stages, managing the opening of windows/tabs etc?

 

I tried placing the shell script in front of the "tell Google Chrome", and then tried with it removed, leaving only the "if" bit, but regardless, Parallels Chrome was activated each time, without a whisper from OS X Chrome.

 

Here be the original script, unedited:

[PS - I realise I could ask these questions in the OP's thread - but I'm not wanting to, since the script works as planned. This scenario might play itself out with other Windows apps as well, where OS X calls Parallels, instead of the native app - so hoping I can use this script to understand what might need to change in the others... Regardless of whether this gets resolved, thanks for all the help so far!]

if application "Safari" is running then
	tell application "Safari"
		try
			set currentSafariURL to URL of current tab of front window
			set pageName to name of current tab of front window
		on error
			return "There are no pages open in Safari at the moment"
		end try
	end tell
	
	tell application "Google Chrome"
		activate
		
		# If Chrome has no windows open make a new window
		if (count of windows) is 0 then make new window
		set currentChromeURL to «class URL » of «class acTa» of front window
		
		# Don't do anything if the page is already open in Chrome
		if currentChromeURL is not currentSafariURL then
			
			# If the active tab is in use make a new tab
			if currentChromeURL is not "chrome://newtab/" then
				make new «class CrTb» at end of every «class CrTb» of front window
			end if
			
			# Open the URL from Safari
			set «class URL » of «class acTa» of front window to currentSafariURL
			
		else
			return "The current Safari tab is already open in Chrome"
		end if
	end tell
	
	
	# Enable the following line to post notifications after sending URLs to Chrome
	--return "Opening '" & pageName & "' in Chrome"
else
	return "Safari is not open at the moment"
end if
Edited by Cassady
Link to comment

I gather the suggested shell script above, was intended to bypass most (if not all) of the current Chrome applescript - but figure that it would interrupt the latter stages, managing the opening of windows/tabs etc?

Yeah. But it would let us know whether it's possible to talk to Mac Chrome when Parallels is up and running.

The problem appears to be that Parallels is registering Win Chrome as "Google Chrome", so all the calls are going to that application. Until that problem is solved, the rest of the script is moot.

There are a couple of other ways to call an application that might work:

1. By bundle id:

tell application id "com.google.Chrome"
…
end tell
2. By path:

tell application "/Applications/Google Chrome.app"
…
end tell
Give those a try instead. Edited by deanishe
Link to comment

Yeah. But it would let us know whether it's possible to talk to Mac Chrome when Parallels is up and running.

The problem appears to be that Parallels is registering Win Chrome as "Google Chrome", so all the calls are going to that application. Until that problem is solved, the rest of the script is moot.

There are a couple of other ways to call an application that might work:

1. By bundle id:

tell application id "com.google.Chrome"
…
end tell
2. By path:

tell application "/Applications/Google Chrome.app"
…
end tell
Give those a try instead.

 

 

LEGEND!  :P

 

 

The second PATH option did the trick! Yay - learnt something! 

 

This was so annoying, since even with Parallels closed/quit, the script would first start it up, and then open Windows Chrome - which saw me waiting, and waiting [1st world problems] and waiting... before I could do anything useful.

 

Thanks for the help! As an added bonus, will be able to fix any others as well, if this happens again.

Link to comment

Yeah. But it would let us know whether it's possible to talk to Mac Chrome when Parallels is up and running.

 

 

 

Just to close this loop, and FWIW - just tried your initial suggestion (with the shell script) - and it works, even when Parallels is closed! 

 

As in, it opens Parallels, then opens Win Chrome, and pastes the Mac Safari url... 

Didn't expect that. 

 

And if I understand things correctly, it does suggest that OS X scripting (in limited(?) scenarios) can be applied to "Windows" applications?

 

Hmm.  Interesting.

Link to comment

I doubt very much that AppleScript will work with Windows applications running in Parallels beyond very basic "open" or "activate" commands (which are performed by the system and don't require an app to be scriptable).

I looked into this a bit. When you run Parallels in shared-application mode, it creates stub Mac applications in ~/Applications, which is what your script was acting upon.

Any scripting that requires explicit support by the application (the AppleScript dictionary David was talking about) almost certainly won't work.

FWIW, you might want to look into editing the stub applications created by Parallels.

You could rename the "Google Chrome" one to "Google Chrome (Win)", for example, to avoid the issue. You'd probably have to edit the Info.plist file inside the app bundle and change the application name in there as well.

Edited by deanishe
Link to comment

FWIW, you might want to look into editing the stub applications created by Parallels.

You could rename the "Google Chrome" one to "Google Chrome (Win)", for example, to avoid the issue. You'd probably have to edit the Info.plist file inside the app bundle and change the application name in there as well.

 

Thanks - I'm going to have to give this a try.

 

After firing up Chrome Safari yesterday, today, it's back to Win Chrome. Not sure how or why, since I never changed anything...

 

Will see if I can manage with the renaming technique, otherwise will fall back to a KeyboardMaestro macro.

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