Jump to content

Get specified characters from your mother's maiden name (etc.)


Recommended Posts

This is a rather basic workflow (primarily an AppleScript script) designed to facilitate logging on to sites which require you to input specified characters from your mother's maiden name, the name of your first school, a memorable date, etc. Some of us use password managers which don't show the numbering of the characters and this workflow is designed to help. I've never used GitHub and certainly don't think this worth "hosting" so please excuse the way in which it's presented. (I shall probably get into trouble for that! ūüėÄ.)

 

It looks like this:

 

Workflow.jpg.472b677cca6113fb1bd6eb80019b08dc.jpg

 

First copy the relevant word to the clipboard from your password manager. The Keyword (I used "gc" for Get characters) to trigger the workflow has no argument and the script will prompt you to provide the numbers of the characters you need (with a space between each number). This is the script:

 

try
    -- get the word from the clipboard
    set theWord to the clipboard
    -- keep it as a title to the dialogue
    set titleWord to theWord
    -- split the word into characters as a list
    set listChars to characters of theWord as list
    -- get the length of the character list
    set lenList to length of listChars
    -- an empty variable to store the characters we need
    set existingChars to ""
    -- set a default answer to demonstrate correct input
    set dAnswer to "1 3 6"
    -- ensure the dialogue shows the word and max. no. of characters
    set userEntry to display dialog ¬
        "Enter the 3 numbers of the characters you want from " & "'" & titleWord & "'" & " with a space between each:" default answer dAnswer with title "Get characters from " & "'" & titleWord & "'" & "(" & "max. " & lenList & " characters" & ")"
    -- get the dialogue input
    set dAnswer to text returned of userEntry
    set astid to AppleScript's text item delimiters
    -- we are splitting the input numbers by the space character
    set AppleScript's text item delimiters to " "
    -- create a list of the input numbers
    set answerList to text items of dAnswer
    set AppleScript's text item delimiters to astid
    -- set variable to check the last number input is not > than number of characters in word
    set overFlow to item -1 of answerList as integer
    -- check the last input number isn't greater than number of characters in the word
    if overFlow is greater than lenList then
        error "There are not " & overFlow & " characters in " & "'" & titleWord & "'"
    end if
    -- now loop for each number in input
    repeat with i from 1 to (length of answerList)
        -- set each number against the appropriate character of the word
        set seekChar to item i of answerList as integer
        if existingChars is "" then
            set existingChars to item seekChar of listChars
        else
            -- add it if we already have a character
            set existingChars to existingChars & " " & item seekChar of listChars
        end if
    end repeat
    return existingChars
    
on error error_message number error_number
    if error_number is -1700 then
    set error_message to "Please ensure there is only a space between the numbers"
    return error_message
    else
    if the error_number is not -128 then return error_message
    -- substitute the following line if not running in an Alfred workflow
    -- if the error_number is not -128 then display alert "Error" message error_message as warning
    end if
end try

 

The script traps certain errors (including incorrect input format or a number greater than the number of characters in the word).

 

I don't know if this will be useful for anyone else but I use it a fair bit.

 

Stephen

Link to comment
3 hours ago, Stephen_C said:

I've never used GitHub and certainly don't think this worth "hosting"


Quite the contrary, sometimes the simplest code is the most useful to someone else. If I had to log in to websites with such requirements, I’d definitely try this out. I see you’re even doing error handling!

 

If you change your mind regarding hosting, the Alfred blog has a post teaching how to share a Workflow on GitHub. It goes from zero‚ÄĒassuming you don‚Äôt even have an account yet‚ÄĒto the simplest path you can take to share a new Workflow. The goal is precisely to get you done fast with something useful to share but that you can improve if you feel like spending the extra time.

 

Even if you elect not to do it, thank you for sharing what you have!

Link to comment
  • 3 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...