Jump to content

Open url open 2 windows


Recommended Posts

I have a few workflows to open specific url's on my macbook.

 

When the browser app has no open windows, the workflow open the correct url but also opens a second windows with the default startpage.

Is there a way I can counter this?

 

When the browser already has an open windows everything works fine.

Link to comment

Hi @HanneMaes, welcome to the forum.

 

Assuming you're using Alfred's own Open URL action, this is something the browser is doing itself. It might be possible to write a custom AppleScript that prevents that behaviour, but that would depend on which browser you're using. When you have a question about an application's behaviour, please always mention which application you're talking about.

Link to comment
8 hours ago, HanneMaes said:

So I guess it's a Firefox issue?

 

Appears so. And you can’t use AppleScript to fix it because Firefox doesn‘t support it.


You should be able to verify it’s indeed Firefox’s issue by opening a terminal and (assuming it’s your default browser) running open 'https://example.com'.


After verification, you should go to Mozilla’s bug reporter, see if the issue is already reported, and report it if it isn’t.


Until it’s fixed (which may never happen), try going around the problem. If the issue doesn’t occur when a browser window is already open, open it yourself with a Launch Apps and Files Action before opening the URL.

Link to comment
3 hours ago, HanneMaes said:

But the workaround isn't working. I'll keep looking for a new workaround.

 

You'll need to add a long enough delay for Firefox to open before opening the URL. If it doesn't have a window open, it will open the extra empty window.

 

Because you don’t want to be waiting a few seconds when Firefox is running, you can use this AppleScript to open your URL:

property _delay_after_launch : 3

on is_running(_name)
	tell application "System Events" to return count of (processes whose name is _name)
end is_running

on run (argv)
	set _url to first item of argv
	set _running to is_running("Firefox")
	log "_running=" & (_running as text)
	if _running = 0 then
		activate application "Firefox"
		delay _delay_after_launch
	end if
	tell application "Firefox" to open location _url
end run

Put it in a Run Script action with Language = "/usr/bin/osascript (AS)" and "with input as argv", then use it instead of the Open URL action (and Launch Apps and Files).

Edited by deanishe
Link to comment
2 hours ago, vitor said:

Why not application "Firefox" is running (returns true of false) instead?

 

Habit, I guess. I just always avoid passing a variable to application because it historically has often not worked.

 

Edited by deanishe
Link to comment

Thanks for the script!

But I can't get it working.

 

The workflow opens Firefox but keeps it minimized, and when I open Firefox it opens the startpage only?

I now have just the Run script action, I deleted the open Url action.
With this code
 

property _delay_after_launch : 3

on is_running(_name)
    tell application "System Events" to return count of (processes whose name is _name)
end is_running

on run (argv)
    set _url to first item of argv
    set _running to is_running("Firefox")
    log "_running=" & (_running as text)
    if _running = 0 then
        activate application "Firefox"
        delay _delay_after_launch
    end if
    tell application "Firefox" to open https://www.blender.org/
end run

 

Link to comment
2 hours ago, HanneMaes said:

With this code

 

Your code is invalid. Alfred is doubtless printing an error message in its debugger, which you should always check when something isn't working.

 

The command is open location, not open (that’s for local files), and you need to put the URL in quotation marks:


tell application "Firefox" to open location "https://www.blender.org"

 

Edited by deanishe
Link to comment
  • 3 weeks later...

Still can't get it to work.

I get this error

/Users/hannemaes/Library/Caches/com.runningwithcrayons.Alfred/Workflow Scripts/1A04F040-6513-45A3-B5C8-3DA9A874F533:196:206: execution error: Can’t get item 1 of {}. (-1728)

And I have this code:

property _delay_after_launch : 3

	on is_running(_name)
    		tell application "System Events" to return count of (processes whose name is _name)
	end is_running

	on run (argv)
    		set _url to first item of argv
    		set _running to is_running("Firefox")
    		log "_running=" & (_running as text)
    		if _running = 0 then
        		activate application "Firefox"
        		delay _delay_after_launch
    		end if
    		tell application "Firefox" to open location "https://www.blender.org"
	end run

 

Link to comment
2 hours ago, HanneMaes said:

Can’t get item 1 of {}. (-1728)

 

Here:

 

2 hours ago, HanneMaes said:

on run (argv) set _url to first item of argv

 

The script I gave you expects you to pass in the URL to open from a previous workflow element.

Link to comment
  • 2 months later...

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