I am new to Keyboard Maestro. I have not had it two weeks now, and I am loving it already. I am looking around the forum and drinking in the knowledge from this great community, already it has been a help. Scripting sounds exciting (I know a good deal of JavaScript from web development), and I look forward to try some.
I have a question about constructing a macro. I have a need to launch files from a directory e.g. Users/pctechtv/Sites, that holds the files I test on my local PHP server. When the files are clicked on they would go to Firefox or any browser with this syntax in the first picture. I would like to know if it is possible to create a macro in Keyboard Maestro to launch the file in Firefox (or browser of choice) with a string replace to change them to what I need (second pic)? This way I won’t have to type them in manually to the address bar every time. I guess this string replace would have to read the file path and change it with regex or something.Thanks
So after reading some more I see you and other members of community have already addressed some of my issues. I am referring to this thread.here There is talk around the idea that Pathfinder does not have good support for AppleScript in other posts. I understand that what I want to do is working with Pathfinder’s menu system so I am thinking the answer is no. But here it goes. Is there a way to turn a Macro like this into a Variable instead of a Clipboard entry? This way I won’t have an entry in the Clipboard (good for not cluttering the history). But if not I can live with it. I need to tweak it so Firefox can open and paste the URL better. It is working 9 out of 10 times. In Safari it is working 3 our 10 times. Thanks
Nice! That was so helpful. I know some other programs on Windows that need that option… Wow! I have only had this program a few days and it is blowing me away. Thanks
A general process I follow that has helped me write macros that work 100% of the time in Safari (my browser of choice) and Path Finder (my file manager of choice):
Add 2s pauses wherever you think they might help.
Test: Does this work reliably?
No: Add more pauses and/or increase the duration of the pauses. Go back to "Does this work … ".
Yes: Reduce pauses by 0.3s until macro is no longer reliable. Then increase by 0.3s. Done.
And:
I generally create variables any time I need to filter or search-and-replace. “Set %Variable%MyNamedVariable% to Clipboard, operate on %Variable%MyNamedVariable%, paste %Variable%MyNamedVariable%” is, IME, more reliable than using just the system clipboard.
And (added after posting):
in Path Finder, I bind a key-chord to commands I use in KMacros, and execute them by having KM type. I cannot explain why, or if, this actually helps at all. IME, it seems to.
(Note that it links to the actual post, so you can see all of it.)
If you're going to use Safari or Google Chrome you can talk to them directly and avoid clumsy paste operations.
tell application "Safari"
activate
set newDoc to make new document
set URL of newDoc to "https://www.google.com"
end tell
So – to put things together:
------------------------------------------------------------
set myPrefix to "http://localhost/~pctechtv"
set AppleScript's text item delimiters to "/Users/pctechtv/Sites"
tell application "Path Finder"
set selItemList to selection
repeat with i in selItemList
set contents of i to myPrefix & (text item 2 of (get POSIX path of (contents of i)))
end repeat
end tell
tell application "Safari"
activate
repeat with i in selItemList
make new document with properties {URL:i}
end repeat
end tell
------------------------------------------------------------
Path Finder's AppleScript support is poor but serviceable for some things.
By "key-chord" I mean what are generally known as "keyboard shortcuts" — the regular keyboard key which, pressed and released at the same time as one-to-four modifier keys, trigger an operation. One of PF's strengths is that it lets one easily assign key-chords to any menu command. This is done at "Path Finder ▹ Preferences ▹ Features ▹ Keyboard".
My suggestion to you is to replace the KM Action "Select Menu in {Path Finder}" with "Type Keystroke {key-chord}" after setting the key-chord in PF prefs to execute the menu item you want. (Of course, PF must be active when the Action "Type Keystroke {key-chord}" is executed.)
I do this with every application that I can. It is identical to the seemingly trivial case of using "⌘c" instead of "Edit ▹ Copy".
Again, I unable to claim that this helps, or explain why it might help — my experience has been that it does make my KMacros more robust. Some of these include a hundred Actions that operate on four applications and process hundreds of files, which seems to me to be complex enough to be a reasonable test of "robust-ness".
I have no doubt that scripting is a better approach, as long as one has a knowledgeable script-writer at hand .
I totally get what you mean and why, I have had similar experiences on Windows with macro programs. I have seen the simulation of keystroke presses or shortcut keys matter. Great to know about! Thanks
Although Keyboard Maestro manages keyboard shortcuts well, it's generally safer to have it select a menu item than to activate a menu item's keyboard shortcut.
I am not surprised to hear that about Firefox. I have some experience writing Mozilla Add-ons and I know they can be a funny animal. Could someone tell me what makes an applications AppleScript support "poor"? Is this something that the program developer has chosen to leave out. Is it that the program was not made in the typical way with Apple's core languages and frameworks like Cocoa and Objective C? I am very curious as I learn Apple's languages and technologies. Thanks