I want to make a sequence of actions pressing one trigger and then unmake that sequence of actions (making the same actions, but the backward path) pressing that same trigger, can I do this?
Can I Use the Same Trigger to Make the Same Macro I Did First, but in Reverse?
It depends what your actions are. I know what it means to reverse simple actions like this:
- click a mouse
- type a key
but I have no idea what it means to reverse an action like this:
- While condition DO statement
- IF condition DO statement
If you tell me what actions you want to reverse, I may be able to solve this for you. I will achieve the result you want, but I won't be doing it the way you are thinking.
Are two simple actions, like "type F" and after "Type A", and the second time I press the trigger the action needs to "type A" and then "Type F"
Are you saying that single key presses are the ONLY actions you want to reverse? If so, this should be easy.
Okay, I've got some code working, as far as I can tell. However it's a little bit annoying because in order to work it uses a left arrow and a right arrow between each keystroke. I didn't realize before I wrote it that it would have this visual anomaly. But at least it works. And there's a very small bug: it won't work if you are in an empty text field (in other words, you need at least one character before your cursor. Otherwise it may transpose two characters that shouldn't be transposed.)
In order to work it has one macro that triggers on a hotkey (I used CTRL-N) and it has another macro that triggers on a typed key. Here's the first macro:
Reverse Hotkey Macro (v10.0.2)
Reverse Hotkey.kmmacros (3.1 KB)
And here's the second macro:
Reverse Macro (v10.0.2)
Reverse.kmmacros (4.7 KB)
Before I investigate how to fix the annoying cursor movement, I'd like to know if this is the functionality you wanted. If I'm doing something wrong, let me know at this point.
I was thiking of some solution more simpler, like use same hot key to trigger two macros, but like a switch, wen you press the firts time, triggers the macro A ( type T, then F), and second time pressed, triggers macro B ( type F, then T)
It's very easy to have a hotkey to switch between two macros. That's trivial. The problem is you want the contents of the macros to change to handle different keys different times. Basically, doing it your way requires editing the macros in real time. That's extremely complicated. My solution has ten simple actions. You won't get it much shorter and simpler than that.
POSTSCRIPT: The KM Editor has an AppleScript dictionary, so it may indeed be possible for a macro to read the actions in Macro A, reverse them, and execute the new macro. Similarly, it would have to create Macro A, and it would have to do that after collecting the keys that you wanted to reverse. I'm not capable of writing that solution for you, but just to let you see what might be involved, here's an XML copy of a single KM action ("Type Return"), which is the kind of thing that a macro (using your approach) would probably have to deal with.
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <array> <dict> <key>ActionUID</key> <integer>9153292</integer> <key>KeyCode</key> <integer>36</integer> <key>MacroActionType</key> <string>SimulateKeystroke</string> <key>Modifiers</key> <integer>0</integer> <key>ReleaseAll</key> <false/> <key>TargetApplication</key> <dict/> <key>TargetingType</key> <string>Front</string> </dict> </array> </plist>
It could be done, but I've never done it, and I think it would take quite a bit more code that my solution required.