Import from QuicKeys?

Since it looks like QuicKeys will soon stop working, and will not be updated, I am searching for an app to replace it. I have a trial version (8.2.4) of KM and it looks like it will meet my needs.

I have 451 QuicKeys macros, nearly all are simple “type it for me” actions. Is there any way to import these to KM without having to manually enter each one?

Thanks.

2 Likes

Hey Bill,

Take note of this if you haven't seen it yet:

Transition_From_QuicKeys

Not unless you can script QuicKeys to extract the abbreviations and substitution text.

OR – it might be possible to build a brute-force macro that does most of the work.

I finally give up on QuicKeys in 2012, so my memory of the nitty-gritty details of how it works is practically nil now...

Can you post screenshots of what a snippet expansion macro and what the macro list looks like?

-Chris

Hey Bill,

I dug out my copy of QuicKeys 4.0.7 and had a look.

It's pretty easy to extract pure text abbreviations from the QuicKeys UI with UI-Scripting, so at the very least your pain of transition can be eased.

QuicKeys can export abbreviations – but the export file doesn't look very friendly – and I personally am not willing to mess with it.

I'll help you with the UI script though, if that's the way you choose to go.

-Chris

I would encourage you to use some of these macros:

To either create a bunch of text expansion macros or to create expansion macros on the fly.

That makes the task of creating the expansions relatively painless, though it is still going to be tedious dealing with 400+ of them.

Yah, I looked at that QC Export file as well, pretty messy. I thought about using some combination of GREP and SED to extract the macro names and text, but it sounds like you have an easier way. My programming skills are pretty rusty, but I am passingly familiar with the Unix shell and AppleScript. I’m not at all sure about getting the data into KM once it’s extracted from QC.

Thanks for any help you can offer.

Bill.

Hey Bill,

Okay, here's a quick and dirty macro that will import QuicKeys abbreviations into Keyboard Maestro.

Select the first Abbreviation in your Abbreviations list:

image

The macro is set to repeat 10 times.

Test it.

If it works decently then change the repeat to something longer, run the macro, and sit back.

The macro will NOT grok styled text or QuicKeys time tokens, so I expect there will be some errors.

Styled text will come through as plain text.

QuicKeys tokens (like time, date, etc) will be gibberish or empty strings.

But hopefully this will work with the majority of your abbreviations.

-Chris


Create Text Expansion From Selected QuicKeys Abbreviation v1.00.kmmacros (8.4 KB)

Wow, thanks for your work on this.

For some reason that I can't recall, I used shortcuts to do my typing. That’s going to seriously complicate things.

I have no problem with doing some hand editing for the ones that don’t copy properly.

Bill

Hey Bill,

If you want to export those and send them to me, I'll take a look-see at what's possible from a UI-Scripting perspective.

-Chris

Well, that was interesting. I had to prune some shortcuts that had passwords and the like. I duplicated the Shortcuts folder and removed anything with sensitive information, but I couldn’t get QK to recognize the new folder. I was using an alias and storing that folder on a thumb drive that I remove and lock up when I leave the house. Upshot is that QK will not let me put that back. I had to put the Shortcut folder in the QK Library folder to get it to load, either the original or pruned file. Odd. I’ll have to work out another way to secure that information.

Anyway, here is the pruned export.

And thank you so much for helping with this.

Bill

Hey Folks,

For posterity here's the final script.

NOTE – This script will ONLY deal with QuicKeys shortcuts of the specific type Bill has posted, and it does NOTHING to filter those shortcuts from other kinds.

Import QuicKeys Type Text ShortCuts into Keyboard Maestro 8.scpt.zip (13.8 KB)

----------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2018/11/18 18:30
# dMod: 2018/11/19 03:31
# Appl: Finder, Keyboard Maestro, System Events
# Task: Import QuicKeys Type Text ShortCuts into Keyboard Maestro 8.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Finder, @Keyboard_Maestro, @System_Events, @Import, @QuicKeys, @Insert, @Text, @ShortCuts
----------------------------------------------------------------

set shortcutsFolderAlias to alias "Mercury:Users:myUser:Downloads:QuicKeys Shortcuts 2:Shortcuts:"
set shortcutsFolderPath to POSIX path of shortcutsFolderAlias

set errorLog to {}
set exportList to {}

set xmlHeader to "<?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>
"

set end of exportList to xmlHeader

set xmlTemplate to "
   <dict>
      <key>Activate</key>
      <string>Normal</string>
      <key>Macros</key>
      <array>
         <dict>
            <key>Actions</key>
            <array>
               <dict>
                  <key>Action</key>
                  <string>ByPasting</string>
                  <key>MacroActionType</key>
                  <string>InsertText</string>
                  <key>Paste</key>
                  <false/>
                  <key>Text</key>
                  <string>%Variable%Text%</string>
               </dict>
            </array>
            <key>Name</key>
            <string>%Variable%Name%</string>
            <key>Triggers</key>
            <array>
               <dict>
                  <key>Case</key>
                  <string>Exact</string>
                  <key>DiacriticalsMatter</key>
                  <true/>
                  <key>MacroTriggerType</key>
                  <string>TypedString</string>
                  <key>OnlyAfterWordBreak</key>
                  <false/>
                  <key>SimulateDeletes</key>
                  <true/>
                  <key>TypedString</key>
                  <string>%Variable%Trigger%</string>
               </dict>
            </array>
         </dict>
      </array>
      <key>Name</key>
      <string>Text Expansion</string>
   </dict>
"

set xmlFooter to "
</array>
</plist>
"

set shCMD to "find " & quoted form of shortcutsFolderPath & " -iname 'ExportedShortcutData.plist'"
set plistFileList to do shell script shCMD
set plistFileList to paragraphs of plistFileList

repeat with thePath in plistFileList
   set contents of thePath to alias POSIX file thePath
end repeat

set AppleScript's text item delimiters to linefeed

repeat with theAlias in plistFileList
   try
      
      tell application "System Events"
         set plData to (get text of property list item 1 of property list file (theAlias as text)) as text
         
         set thePlist to make property list item with properties {text:plData}
         set plistRecord to value of thePlist
         
         set textExpansion to TypeTextArchiveTextToType of ShortcutStepArchivePluginStep of item 1 of ShortcutArchiveSteps of plistRecord
         
         set AppleScript's text item delimiters to ".qkshortcutd"
         
         tell application "Finder"
            set abbrevName to text item 1 of (get name of theAlias's parent's parent)
         end tell
         
         copy xmlTemplate to tempXmlTemplate
         
         set tempXmlTemplate to kmReplace("%Variable%Name%", abbrevName, tempXmlTemplate, true, false, false) of me
         set tempXmlTemplate to kmReplace("%Variable%Text%", textExpansion, tempXmlTemplate, true, false, false) of me
         set tempXmlTemplate to kmReplace("%Variable%Trigger%", "", tempXmlTemplate, true, false, false) of me
         
         set end of exportList to tempXmlTemplate
         
      end tell
      
   on error
      set end of errorLog to contents of theAlias
   end try
   
end repeat

set end of exportList to xmlFooter

set AppleScript's text item delimiters to ""
set exportXML to exportList as text

set exportXML to kmReplace("&", "%26", exportXML, true, false, false) of me

tell application "Keyboard Maestro"
   importMacros exportXML
end tell

----------------------------------------------------------------
--» HANDLERS
----------------------------------------------------------------
on kmReplace(findPattern, replacePattern, dataStr, regExBool, caseBool, tokensBool)
   tell application "Keyboard Maestro Engine"
      set foundDataList to search dataStr for findPattern replace replacePattern ¬
         regex regExBool case sensitive caseBool process tokens tokensBool
   end tell
end kmReplace
----------------------------------------------------------------

Bill's zipped QuicKeys export file looks like this:

QuicKeys Shortcuts.qkmx.zip

And if unzipped with the Mac's built-in unzip tool, it actually decodes the export file as well:

image

The script above requires the user to give it an alias to the “Shortcuts” folder as seen in the above folder structure.

On my system the script when run from Script Debugger took about 30 seconds to import 450+ QK type-text shortcuts into Keyboard Maestro.

I cribbed from the second of Peter's posted macros above to write the import section of the script.

Keyboard Maestro balked initially on the import, because the XML contained unencoded ampersands (“&”) in some URLs – but I was able to encode them to “%26” to get around that.

-Chris

This worked very well. Thanks Chris. I have discovered a couple minor glitches, like a missing tab, but nothing significant. Saved me tons of work. I’ve switched over to KM completely so that when QK quits working it won’t be a problem. :smiley:

Hi, I'm a new user of KM and old one of QK. I've found an easy way to import my macros from QK to KM. Create a new empty macro in KM then click "RECORD" switch to the app where you will use the QK macro and type the QK command of the action you wish to record, at the end stop recording on KM and yo macro will be there (almost perfect).
This is a stupid idea but worked for me :wink::grin:
Hope will help somebody
Guido