Using Hook with the Trello App

Answering my own question, here is a simple “Get Address” script to get started on the path of using trello, using the same structure @Heikau used in his “Forklift” script.
It’s ugly UI Scripting, but it works.

activate application "Trello"
tell application "System Events"
	tell process "Trello"
		set the clipboard to ""
		delay 0.3
		click menu item "Copy Current URL" of menu 1 of menu bar item "Edit" of menu bar 1
		delay 0.3
		set theURL to the clipboard
	end tell
end tell
return theURL

This returns a URL, though, so it won’t be opened in the Trello App but in a browser.
Obvious improvements would be to :

  • get the name of the card
  • open the link in trello.app

There is a trello API that could theoretically be used for this, because you can reference the card from a short link that’s embedded in the card url. I’d need to practice my regex game in applescript, then call the API. Not sure I have the time and/or the chops …

1 Like

Thanks for this, @seishonagon.

We here had suspended work on this thinking there was no API. Would love to have Trello app integration. We will have another look.

This helps me - as a new Hook user - as I track GitHub issues, Trello cards for those issues, and OmniFocus tasks for those same issues.

(Yeah, I know…) :slight_smile:

Question, though: Why did you need to clear the clipboard before copying the URL to it? Is there something subtle/wrong with Trello?

No, I copy pasted the original apple script from @Heikau with little thought :slight_smile: don’t change what’s not broken… especially in apple script

1 Like

So that costs you a delay of 0.3s… :slight_smile:

Funnily enough my “delay of choice” is 0.2s. And if that doesn’t cure it there’s usually something more significant wrong… :slight_smile:

1 Like

I’ll check without it to see if it works. You’re probably right …

1 Like

Trello does have Copy current link menu item. The URL it returns is a web URL.

If a Trello app user would test the script below and give us feedback, that would be great.

#get address
set the clipboard to ""


tell application "System Events" to tell process "Trello"
		keystroke "c" using {option down, command down}
		delay 0.1
		repeat 10 times -- poll clipboard for ~2.5 seconds. Sometimes set x to
teh clipboard throws exception
				try
						set newsUrl to the clipboard
						if newsUrl is not equal to "" then
								exit repeat
						end if
						keystroke "c" using {option down, command down}

				end try
				delay 0.1
		end repeat
		set newsTitle to name of window 1
		set AppleScript's text item delimiters to {"/"}

end tell

set prevTIDs to text item delimiters of AppleScript
set text item delimiters of AppleScript to "/"
set reverseUrl to "" & reverse of text items of newsUrl
set text item delimiters of AppleScript to prevTIDs

set theOffset to offset of "/" in reverseUrl

if result is not 0 then
		set theOffset to (count (reverseUrl)) - theOffset
		set newsUrl to text 1 through theOffset of newsUrl
end if

return "[" & newsTitle & "](" & newsUrl & ")"

If anyone would like to put a feature request to the Trello folks to automate Copy Link that would be helpful. If they have an open issue tracking system or forum, that could be upvoted. It would also be better if their Copy Link returned a universal URL such that users could open the link in their app if it’s installed/preferred.

It doesn’t work as-is. Hook doesn’t recognize the window.

However this works:

  • For Get Adress

      activate application "Trello"
      tell application "System Events"
      	tell process "Trello"
      		set the clipboard to ""
      		delay 0.3
      		keystroke "c" using {option down, command down}
      		delay 0.3
      		set theURL to the clipboard
      	end tell
      end tell
      return theURL
    
  • For Get Name

      activate application "Trello"
      tell application "System Events"
      	tell process "Trello"
      		set theName to name of window 1
      	end tell
      end tell
      return theName
    

Also, I’ve sent a ticket to trello requesting automation. Let’s see!

Sounds like you’re both dealing with flakiness in Trello. :frowning:

thank you all for the feedback and scripts. I tried Trello a while back but only used the web version, with which Hook is compatible. What are the advantages of using their app?

Frankly, none that I can see. I suspect it’s a thinly disguised wrapper for the web version anyway. I get more flexibility using Trello with a chromium browser (Vivaldi is nice) and a few extensions …

1 Like

I’ve got a reply from Trello pointing me to their API which allows one to do pretty much anything - including getting the link and name of a card.
The API documentation is located at: https://developer.atlassian.com/cloud/trello/rest/api-group-actions/

HTH

1 Like

Thank you for asking them and the info. Much appreciated!

1 Like