Jump to content

Kassi

Member
  • Posts

    6
  • Joined

  • Last visited

Posts posted by Kassi

  1. I don't think this is possible with the standard bookmark feature of Alfred.

     

    I have an AppleScript in my workflows that does exactly this: open a set of URLs in a browser (Chrome in this case) and check whether it's already open. Works of course with only one URL.

    If you can create a workflow triggered by a keyword that actually searches for bookmarks and passes the selected one to the AppleScript action, then it may work.

     

    Here's the script (you can probably reduce it if you don't need the option to open several URLs in Tabs):

    on alfred_script(q)
    	set old_delimiters to AppleScript's text item delimiters
    	set AppleScript's text item delimiters to ","
    	set the_urls to every text item of q
    	set AppleScript's text item delimiters to old_delimiters
    	set first_url to first item of the_urls
    	
    	set the_window to find_url_in_windows(first_url)
    	repeat with the_url in the_urls
    		find_or_open_url_in_current_window(the_window, the_url, true)
    	end repeat
    	set the_window to find_url_in_windows(first_url) -- reactivate
    end alfred_script
    
    on find_url_in_windows(the_url)
    	set window_index to 1
    	set found to false
    	tell application "Google Chrome"
    		repeat with the_window in windows
    			set found to my find_or_open_url_in_current_window(the_window, the_url, false)
    			if found then
    				return the_window
    			end if
    			set window_index to window_index + 1
    		end repeat
    		set the_window to front window
    		open location the_url
    		return the_window
    	end tell
    end find_url_in_windows
    
    on find_or_open_url_in_current_window(the_window, the_url, open_if_not_found)
    	tell application "Google Chrome"
    		set tab_index to 1
    		repeat with the_tab in tabs of the_window
    			if (URL of the_tab) starts with the_url then
    				activate
    				tell the_window
    					set active tab index to tab_index
    					set index to 1
    				end tell
    				tell application "System Events" to tell process "Google Chrome"
    					perform action "AXRaise" of window 1
    				end tell
    				return true
    			end if
    			set tab_index to tab_index + 1
    		end repeat
    		if open_if_not_found then
    			open location the_url
    			return true
    		end if
    		return false
    	end tell
    end find_or_open_url_in_current_window

     

  2. I have a workflow that starts up several apps / windows and calls a run script action after each to place it.

    In one of my current workflows I'm opening 2 separate Safari windows and want to place them side by side.

    The Hotkey triggers several Arg and Vars actions (setting the position for the application - 2 of them are for the Safari windows), which call a Run NSAppleScript to open a URL in Safari (or opening the corresponding window if it is already open), followed by a Run Script to place the window (via hammerspoon).

    It seems that the Arg and Vars and/or NSAppleScript actions run somehow in parallel because when the placement action of the first Safari window wants to place the window, it can only look for the frontmost "Safari" window which turns out to be secondly opened window already most of the times.

    Is there any way to tell the workflow to please finish one path before continuing with the next to avoid mismatch?

  3. I created a bunch of workflows helping me with my daily routine.

    For that I use custom scripts, e.g. to place applications in a certain layout.

    As an example I have one "Run script" action which calls hammerspoon and places windows according to arguments given via environment variables I set with "Args and Vars" utility. By that I can reuse my script and "just" have to configure it for each application window I start in my workflow.

    It would be nice create a real action out of this with a custom dialog so I don't have to mess arround with entering the names and values in variables (which are alphabetically ordered, not logically), but rather have my own dialog with 6 fields or even some predefined positions I can choose from.

     

    Is there any way of adding "custom actions"?

×
×
  • Create New...