Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

thomasnield
Copy link

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?

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?
@gineer01
Copy link

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?

@thomasnield
Copy link
Author

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,

}

@thomasnield
Copy link
Author

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

@gineer01
Copy link

The use case for date/time and random string is interesting. Thanks for the examples!

@thomasnield
Copy link
Author

@ChillarAnand
Copy link

This PR seems to be old. Any plans on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants