Assign keystroke to IDEScript [solution for Macs]

Can you assign a keystroke to an IDEScript? For example, some apps like you make the keyboard shortcut part of the name of a file so it will respond to that shortcut within the app.

I ask because I’d like to tie control-U to my Uppercase Selection script, and control-L to my Lowercase Selection script. I can probably do it through the OS, but wanted to see if Xojo provides a way first.

No

Not that I ever found. I’d be interested in seeing what you come up with! I do some coding with voice and use Dragon Dictate to access the File > IDE Scripts menu, particularly my Format Code script. It however has a nice menu picker in it. Didn’t have to code anything.

I am sure there are some cool keyboard shortcut tools out there to help out, just never researched them. Please let us know what you find!

My first choice, using the OS to assign a keystroke to the menu item, failed. I can assign and use the keystroke (ctrl-L, in this case), but instead of running the script, it opens it for editing, the same as if I had held down the command key when choosing it from the menu.

Those items are dynamically added so I doubt the OS knows they exist when starting the IDE
So I doubt that assigning them in the OS X preferences pane will work

Again, it DID work, and even showed the shortcut next to the name of the script in the menu. But it only opened the script for editing rather than running it.

Which says it didn’t work :stuck_out_tongue:
If it had “worked” it would have done as you intended
Imagine if we said “Hey you pressed Compile but we saved it as an XML project - close enough!”

There are two parts here.

First, assigning the keystroke. That worked, keystroke assigned. I interpreted your post to mean that the OS wouldn’t be able to find the menu item at all (you said, “Those items are dynamically added so I doubt the OS knows they exist when starting the IDE So I doubt that assigning them in the OS X preferences pane will work”), and that’s not the case.

Next, getting the script to run when the keystroke is used. That part “works” in that something happens, but it’s the wrong thing. That says to me that the OS is doing what it should but the IDE is somehow misinterpreting it.

Anyway, at this point we may be arguing semantics. It’s not a solution in any event, so I’m still looking for one. I may file two Feature Requests, one to “fix” the current behavior (if I’m right about the IDE not behaving as it should), and the second to allow the assignment of keystrokes to scripts. The latter would solve the problem universally.

cmd-L is already used so that is probably an issue

The OS X pane requires the exact name because it actually hunts it down using the text of the item - not what I expected or recalled
So on that count I am wrong

I haven’t looked into the code for opening & running a script in a while so I’m not sure why it’d fail to run if you had a short cut vs just selecting it in the menu

But I’ll keep the “hey it did something so it must have worked” explanation in the back of my head for bug reports :stuck_out_tongue:

Oh - and FR’s need to go in via feedback :slight_smile:
See #6649

I tried Control-L, not Command-L, so there was no conflict on that count. (On a Mac, of course.)

You can make an app to do this fairly easily, the tricky part is having your app running when Xojo is. In the app, register a global hotkey, when triggered check that Xojo is frontmost then send the IDEscript with applescript or the Xojo socket thingy. I use this for a text expansion IDEscript, moving from the method name field to the parameters field and closing the bottom pane, though those last two are just mouse events. I get the app almost always running with Xojo by using it to launch Xojo and repointing project files to open with it. Circuitous but if you really want it it can be done.

Look at TextExpander https://smilesoftware.com/TextExpander/features.html.
Says it can invoke applescripts from keystrokes.

I’ve tried the System Preferences menu addition and get the same behavior. First time the script runs until Xojo is restarted then the script just opens.

Being able to assign a keystroke to a script in Xojo would go a long way to making the Xojo editor much more powerful. Maybe I’m use to Vim and Emacs, but being able to write a method, then assign it to a short cut just about seems an essential to me. Everyone works differently, being able to make Xojo work for them would be awesome.

<https://xojo.com/issue/33299>

You can send an IDEScript to the IDE with AppleScript? What’s the syntax?

Kem, for what it’s worth, it works great here. I went to Control Panel > Keyboard > Shortcuts > App Shortcuts. Added Xojo. I then typed in the name of my menu “Format Code.xojo_script” and assigned the shortcut Ctrl+L.

In the code editor, I hit Ctrl+L and everything is beautified!

Now, this does nothing for my Windows friends.

hence why I said see #6649

Can you repeat the keystroke? I wonder what the difference is?

Yup. I tried quitting and restarting Xojo as well, and it still works. Thus far I have not been able to make it goof. Mind sharing your script? I’ll put it on and bind it just as you did. You can try mine, if you’d like: GitHub - jcowgar/xojo-format-code: Code formatter written in XojoScript for Xojo

This is the thread where Joe Ranieri posted the form I use
https://forum.xojo.com/2054-here-is-a-script-to-build-projects-from-command-line-osx

tell application "Xojo" «event RBaescpt» "beep" end tell

This looks relevant to
https://forum.xojo.com/3849-how-to-use-applescript-for-building

This is my current script

IDEScriptTrigger2.scpt on run {appPath, script_contents} tell application appPath «event RBaescpt» script_contents end tell end run

and calling it…

IDEScriptTrigger2("KM:Applications:Xojo 2014 Release 1:Xojo 14r1.app", currentScriptSource)
currentScriptSource is just a string read from the IDE Script file. A specific Xojo path is used because I have a couple copies of Xojo, the hardcoding is laziness.

A previous simpler version that doesn’t target a specific Xojo app

[code]IDEScriptTrigger.scpt
on run {script_contents}
tell application “Xojo”
«event RBaescpt» script_contents
end tell
end run

IDEScriptTrigger(currentScriptSource)[/code]

When debugging with this you’ll get errors from the applescript, it’s a known issue I guess and can be ignored, the script gets run.

Thanks Will, that may be one solution.

By the way, you’re safer calling apps by their bundle id rather than by name. The syntax is almost the same, but it would be tell application id "com.xojo.xojo"….

Jeremy, here are the two simple scripts I tried. I’ll try yours in the morning.

https://dl.dropboxusercontent.com/u/26920684/Uppercase%20Selection.xojo_script

https://dl.dropboxusercontent.com/u/26920684/Lowercase%20Selection.xojo_script