Working hard to learn the syntax of KM, but I need help on this macro. Any takers?

I want to make a macro that works like this:

IF a new file is added to my downloads folder
AND
IF that file has the extension .torrent
THEN (in order):

  1. that torrent file should be opened with the default torrent application
  2. the vpn application is opened
  3. a three second pause occurs
  4. the "connect" button on the vpn to be pushed

I've already got the trigger, and 2-4 figured out. The problem I'm having is figuring out what actions to use to identify which file is a .torrent, and how to then open that particular file. I'd really love some insight from you veterans here.

This is only one piece of a much more complex macro that I want to create so it can handle contingencies like if my torrent app is already running but my vpn isn't, but once I get this down, I think I can do the rest.

I appreciate you guys a ton!

Assuming the trigger you have figured out is the Folder trigger, I think this example should solve the last piece of your puzzle:

Open Newly Downloaded Torrent Files.kmmacros (2.4 KB)

Thanks! I'm surprised it would be this simple!

I'm wondering, concerning the range of possible things the %TriggerValue% variable can refer to, do we just assume that the program is looking at the name of the file as opposed to any other attribute of the file (e.g. the name of it's containing folder, or the first line of text in the file, or the date it was last modified, or....)?

I think my hangup is understanding the way variables work, and reading the handbook for the program didn't clarify it much for me.

I know this must be an annoyingly rudimentary question. So thanks for being cool and patient.

I know, tbh looking at the solution is not intuitive enough for a first timer, including me.

Not at all. We've all got to start somewhere.

To clear up one point, %TriggerValue% is not a variable. You're far from the first one to confuse the two given the similar syntax, but it's actually a token. Essentially, that means it will always return one of several pre-defined pieces of data, whereas variables can be set to any kind of text that you want. As it says on the Trigger Value token page on the KM wiki, when used with the Folder trigger, %TriggerValue% always returns the path of the file that was added or removed. You can see this for yourself if you include a Display Text action in the macro with %TriggerValue%, or if you save the information %TriggerValue% returns to a variable and look at it in KM's preferences.

1 Like

The TriggerValue token can be confusing, since its value depends on the context in which it is used. See the above link for details.

But to clarify a few things about %TriggerValue%

  1. It is a KM Token, NOT a KM Variable.
    • Tokens are much like classical programming functions, in that they return a value at run time based on the current environment.
  2. In this case, when using Folder trigger, it returns the FULL PATH of the file added to the folder.

Variables in KM work much like variables in any other programming language, with a few exceptions:

  1. The can contain ONLY strings (text)
  2. Their default scope is "Global", even persisting across Macros and macOS boots.

For details, see

1 Like