Jump to content

Recommended Posts

  • 2 weeks later...
  • 1 month later...
Posted

@vitor i hope you can forgive me pinging you and for reopening this, but I remember why I asked this question in the first place. I’ve been puzzling over building a workflow where I need to be able send keys from the numpad. but in this workflow the user has to have the option of inputting a numerical value from 0 - 32000. I was inspired by your Tapback Message workflow where the key combo gets overwritten by the input but as far as I can tell, there is no way to have the number in the variable be a numpad number.

 

My workaround for this might be having an osascript send key codes, but I would have to have the user type and string of numbers 0 - 32000 and have them replaced by their respective keycodes. There is where I’m getting a little stuck. I could build a list filter where 0 - 9, and replaced with their respective key codes as their argument. I guess I don’t know how to account for the possibility of the input possibly being a 1 digit number, 2 digit number, 3 digit number, 4 digit number, or 5 digit number.  I guess I would have to build the list filter with all 32000 permutations and have them be comma separated and use the split argument utility?

 

Is there a way to send them as multiple arguments where as a script could just send a keycode for 1 key all the way up to 5 keys? My lack of experience is halting me here but maybe not my imagination I guess.

 

And for context — i have a shell script with multiple variables that would run right after these keycodes are sent.

 

I hope i’m making sense.

Posted

I’m not at my Mac right now, but the way that should work is to take the user input (a string of digits), split it (get an array of characters), then run a loop where for every item in the array you check if it’s equal to a number and if so send that key code.

 

Let me know if you can work with that. If not, I’ll take a look later.

Posted

Thanks. I think that is above my brute force and limited skillset but happy to learn if you have the time.

 

I managed to get a little further down the road yesterday but it is not an efficient solution. I thought it would also help me clarify what I’m up to. Pro Tools, the digital audio workstation I use, opens a marker window on the timeline by typing (all on the number pad)

 

decimal point

marker number

enter key

 

so typing

. 10 enter

opens up marker number ten.

 

I have a separate script that runs after the marker window is open and copies two text fields, saves them to variables, and then writes them to a taskpaper file or text file.

 

My less than efficient solution last night was using snippets to replace the actual number with the numpad key code, separate them with commas, pass them through the split utility and then pass them as arguments to an osacript:

on run argv
  set number1 to item 1 of argv
  set number2 to item 2 of argv
  set number3 to item 3 of argv
tell application "System Events"
   key code 65
   key code number1
   key code number2
   key code number3
   key code 76
end tell
end run

 

As you can see I tried this with numerical values that were 3 digits. I couldn’t figure out how to get it working with digits that could be 1 digit up to 5 digits in length. the above script fails unless the number is 3 digits long.

 

Posted

This is vey much untested (I have neither Pro Tools nor a keyboard with numpad), but what I was suggesting was something like:

 

const systemEvents = Application("System Events")
const keycodeNumpadMap = {
  "0": 82,
  "1": 83,
  "2": 84,
  "3": 85,
  "4": 86,
  "5": 87,
  "6": 88,
  "7": 89,
  "8": 91,
  "9": 92,
  ".": 65
}

function run(argv) {
  argv[0].split("").forEach(character => {
    systemEvents.keyCode(keycodeNumpadMap[character])
  })

  systemEvents.keyCode(76)
}

 

This is using /usr/bin/osascript (JavaScript).

Posted

It is a little slow as I have some delays from debugging that I want to play with removing but this is the back end if you are curious:


image.thumb.png.40301e013f57404e05add4b8c57ea0f3.png

 

image.thumb.png.1559945abd3e4d23b3af7044ddf7af72.png

 

na is the CLI tool that brett terpstra wrote to write to taskpaper files but i also mirrored it in plain text files using alfred's write to text file -- which is also useful

Posted

You don’t need the export PATHAlfred already includes those. You also shouldn’t need those variable assignments, they don’t look like they’re doing anything. In short, the last line should be enough for everything.


I’m wondering why you split the flow of objects into a new line halfway, as opposed to just continuing to the right. Doesn’t make a difference, I’m just curious if it was to make the screenshot easier to understand see or if there’s another reason.

Posted
2 hours ago, vitor said:

You don’t need the export PATHAlfred already includes those. You also shouldn’t need those variable assignments, they don’t look like they’re doing anything. In short, the last line should be enough for everything.

 

I didn't realize that. I learn something new everyday! And even just a few years ago I don't think I would have been able to build something like this thanks in part to this forum.

 

2 hours ago, vitor said:


I’m wondering why you split the flow of objects into a new line halfway, as opposed to just continuing to the right. Doesn’t make a difference, I’m just curious if it was to make the screenshot easier to understand see or if there’s another reason.

 

Not for the screen shot, but I like to be able to see the entire flow at a glance if possible. I have 2 x 27" displays and I like to see it all on one. If don't have to scroll, I choose not to scroll!!!!

 

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...