-
Notifications
You must be signed in to change notification settings - Fork 140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HammerText Text Expansion #264
base: master
Are you sure you want to change the base?
Conversation
I was a [heavy AutoHotkey user](https://www.autohotkey.com/docs/Tutorial.htm#s2) on Windows and finding Hammerspoon is the closest replacement for it on Mac. I think there needs to be a text replacement spoon and I found one in this snippet here. https://gist.github.com/maxandersen/d09ebef333b0c7b7f947420e2a7bbbf5 Can we implement this officially as a spoon?
Mac OS already has this functionality out of the box as explained here: https://www.techradar.com/how-to/computing/apple/how-to-use-text-shortcuts-on-mac-1308652 . Does this spoon offer advantages over that functionality? |
I know that... but what about text replacements that are not static or literal strings? Like dates, random string generation, auto incrementing, etc... For example, my big use when writing technical books with lots of figures is generating random strings of alphanumeric characters to assign as figure ID's. I don't know if this is possible to do with Mac's built-in features, at least not easily and without tons of back-and-forth between shell scripts and Automator. function randomStr(keyLength)
local upperCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
local lowerCase = "abcdefghijklmnopqrstuvwxyz"
local numbers = "0123456789"
local characterSet = upperCase .. lowerCase --.. numbers
local output = ""
for i = 1, keyLength do
local rand = math.random(#characterSet)
output = output .. string.sub(characterSet, rand, rand)
end
return output
end
-- Text replacement
ht = hs.loadSpoon("HammerText")
ht.keywords = {
["[name"] = "Thomas Nield",
["[date"] = function() return os.date("%m/%d/%Y") end,
["[time"] = function() return os.date("%I:%M %p") end,
["[randstr"] = function() return randomStr(10) end,
} |
As far as I can tell doing another Google search, again it's just a lot of clicks and separate applications with Automator... building all this functionality with disparate scripts, UI wizards, and allowing permissions. It would be nice if this was a one-stop shop with HammerSpoon where I can add a text replacement function to my other automations without all that UI hassle. https://www.techradar.com/how-to/computing/apple/how-to-use-text-shortcuts-on-mac-1308652 |
The use case for date/time and random string is interesting. Thanks for the examples! |
This PR seems to be old. Any plans on this? |
@thomasnield I know it's taken us a while to get to it, but do you want to proceed with this PR? If so, it will need to be updated to contain the source. The zip files are managed automatically, so you need to put the source for the Spoon in the Also, just from a quick look, your docstrings probably aren't going to pass the linter, I would suggest trying to make them more like the ones used in other Spoons. |
I was a heavy AutoHotkey user on Windows and finding Hammerspoon is the closest replacement for it on Mac. I think there needs to be a text replacement spoon and I found one in this snippet here.
https://gist.github.com/maxandersen/d09ebef333b0c7b7f947420e2a7bbbf5
Can we implement this officially as a spoon?