10

It would be great if AppleScript could exercise more control over Orion, especially executing JavaScript (in Safari, this command is "do JavaScript" and in Chrome it's "execute", with the ability to specify the tab or document). Automation is a power-user sort of thing and so seems right up Orion's alley!

    I also think being able to control Orion via AppleScript would be very useful and add a lot of productivity. I had opened a similar feature suggestion some time ago (https://orionfeedback.org/d/1002-command-line-options-to-open-url-in-new-tab-or-window), in order to be able to control Orion via command-line options, similar to Firefox), e.g. to open a certain web page from an xbar menu item.

    Having such functionality exposed via AppleScript would be a viable route as well. Even from shell scripts, one use osascript to call such AppleScript actions.

    • Vlad replied to this.

      Noy Orion does support AppleScript to certain extent. AppleScript has a ton of commands. We are adding them one by so please be specific.

        The top command I'd personally like to see is "do Javascript" as it is implentend in Safari. Here's a screenshot of the command in Safari's AppleScript library:

          12 days later

          I agree about appleScript. Probably the best practice would be to try to implement the same commands and behavior as Safari and/or Chrome.

          Might I also suggest as a resource for you in the implementation:

          https://forum.latenightsw.com/

          The site is run by a couple of mac automation experts and there's a lot of AppleScript experience among the members.

          Also, here:

          https://macscripter.net/search.php?action=show_new

          There is an ongoing discussion about scripting Orion, and issues with getting results from specific commands.

          Hope that's helpful

          • Vlad replied to this.
            11 days later

            CarbShark Our approach is to implement commands one by one as they are requested (and desired by number of upvotes). We could easilly spend a month implementing all commands and we dont have that time given 1,500+ other issues on this site.

              7 months later
              a month later

              Here's an example that works with Chrome, Brave, and Edge (the latter two with slight modifications). They all include the Chromium Suite. Safari includes the Safari Suite and a very similar AppleScript works for it.

              This script is passed three variables from Keyboard Maestro: local_Url, local_UrlPattern, and local_ReloadTab. The script function is simple...

              If the browser includes a window with a tab URL that matches local_UrlPattern (RegEx), then that tab is activated. If local_ReloadTab is "1", then the activated tab is reloaded.

              If a match is not found, the browser opens local_Url in a new tab.

              use AppleScript version "2.4" -- Yosemite (10.10) or later
              use scripting additions
              use framework "Foundation"
              
              ### Requires Keyboard Maestro 8.0.3+ ###
              set kmInst to system attribute "KMINSTANCE"
              tell application "Keyboard Maestro Engine"
              	set kmUrl to getvariable "local_Url" instance kmInst
              	set kmUrlPattern to getvariable "local_UrlPattern" instance kmInst
              	set kmReloadTab to getvariable "local_ReloadTab" instance kmInst
              end tell
              
              property NSRegularExpressionSearch : a reference to 1024
              
              if kmUrlPattern ends with "/" then set kmUrlPattern to text 1 thru -2 of kmUrlPattern
              set windowIndex to 1
              
              tell application "Google Chrome"
              	repeat with theWindow in windows
              		set tabIndex to 1
              		repeat with theTab in tabs of theWindow
              			set theTabURL to URL of theTab
              			if theTabURL ends with "/" then set theTabURL to text 1 thru -2 of theTabURL
              			if (my regexMatch:theTabURL withPattern:kmUrlPattern) then
              				activate
              				tell window windowIndex
              					set active tab index to tabIndex
              					set index to 1
              				end tell
              				tell application "System Events" to tell process "Google Chrome"
              					perform action "AXRaise" of window 1
              				end tell
              				if kmReloadTab is "1" then
              					tell the active tab of its first window to reload
              				end if
              				return
              			end if
              			set tabIndex to tabIndex + 1
              		end repeat
              		set windowIndex to windowIndex + 1
              	end repeat
              	open location kmUrl
              end tell
              
              on regexMatch:theText withPattern:thePattern
              	set thePattern to "^" & thePattern & "$"
              	set theText to current application's NSString's stringWithString:theText
              	set theRange to theText's rangeOfString:thePattern options:NSRegularExpressionSearch
              	return (|length| of result) > 0
              end regexMatch:withPattern:
              • Vlad replied to this.
                11 days later

                Jims Please specify exactly what commands are broken in Orion

                  a year later
                  3 months later
                  17 days later
                  No one is typing