Start a new topic

Option to start connection with application

When starting Royal TSX it would be helpful if there were an option to have a connection, or multiple connections, start automatically. On macOS every time I use Royal TSX I connect to the local terminal and two other machines, one ssh and one RDP. I have many other connections in Royal TSX that I open when needed, but to have these 3 start with the application would be a big time saver.


Hi Mark,


you could write a short AppleScript that launches Royal TSX and starts the connections you want.

This should be easily doable in a couple of lines.

Here's a link to get you started using the AppleScript scripting interface: https://www.royalapps.com/go/kb-ts-mac-applescript-samples


Hope that helps!


cheers,

Felix

Thanks Felix,

I was able to create an AppleScript and then a shortcut in the Shortcuts.app below:

on run {input, parameters}
	tell application "Royal TSX"
		-- Replace 'Terminal' with the name of the connection you want to open
		set targetName to "Terminal"
		
		-- Get the ID of the connection whose name matches the target name
		set conIds to id of every connection whose name is equal to targetName
		
		-- If there's a matching ID, connect
		if (count of conIds) > 0 then
			set conId to item 1 of conIds
			connect conId
		else
			display dialog "No connection found with the name: " & targetName
		end if
	end tell
	
	return input
end run

Using a shortcut or a script, even when saved as a .app, isn't the most efficient solution to this problem. A more intuitive approach would be to incorporate a checkbox within a connection's properties or an option to select apps for startup under Settings > General > Start and Quit. This would let Royal TSX stay docked and launch normally, eliminating the need to run separate apps, scripts, or shortcuts.

The best alternative I've found so far to use Hammerspoon with the following init.lua

function applicationWatcher(appName, eventType, appObject)
    if (eventType == hs.application.watcher.launched) then
        if (appName == "Royal TSX") then
            local applescriptCode = [[
                tell application "Royal TSX"
                    -- Replace 'Terminal' with the name of the connection you want to open
                    set targetName to "Terminal"
                    
                    -- Get the ID of the connection whose name matches the target name
                    set conIds to id of every connection whose name is equal to targetName
                    
                    -- If there's a matching ID, connect
                    if (count of conIds) > 0 then
                        set conId to item 1 of conIds
                        connect conId
                    else
                        display dialog "No connection found with the name: " & targetName
                    end if
                end tell
            ]]
            local ok, result = hs.osascript.applescript(applescriptCode)
            if not ok then
                hs.notify.show("AppleScript Error", "Failed to run the script", result)
            end
        end
    end
end

appWatcher = hs.application.watcher.new(applicationWatcher)
appWatcher:start()

 

Login or Signup to post a comment