applescript keystroke using
Okay, this is a bit strange???it seems to just repeat what you say back to you. After a bit of playing, I understand what??s going on. Some of the methods aren??t executed until you explicitly tell them to execute.
Technically, what happens is that all ‘property’ and ‘element’ methods return an Appscript::Reference instance; only ‘command’ methods actually send an Apple event to the target application.
Apple event IPC is quite unusual in that it’s actually based on remote procedure calls plus queries, rather than the more common object-oriented approaches used by COM, CORBA, Distributed Objects, etc. As you say, this is for sake of efficiency: Mac OS 7-9 had pretty awful multiprocessing support, and context switches were very expensive and limited to a maximum of 60 per second. The query-based “do more with less” approach minimises the number of Apple events that need to be sent to get things done. Takes a bit of getting used to if you’re coming from an OOP background, and isn’t without its problems (it’s notoriously tricky to implement reliably on the application side), but when it does work it’s really quite elegant.
Anyone who knows how to programatically create a new tab, feel free to chime in on the comments, and I??ll update the script.
Looks like Terminal’s ‘make’ command is broken, unfortunately; normally I’d expect at least one of the following to work (depending on how the application likes the insertion location constructed):
app('Terminal').make(:new=>:tab, :at=>app.windows[1])
app('Terminal').make(:new=>:tab, :at=>app.windows[1].tabs.end)
but neither of these worked, nor did any other variations I tried. I also tried making new windows, but that returned errors too:
app('Terminal').make(:new=>:window)
app('Terminal').make(:new=>:window, :at=>app.windows.end)
It’s frustrating, but as longtime AppleScripters can tell you, these sorts of obvious bugs are unfortunately not that uncommon, even in Apple applications. All I can suggest is filing a bug report with Apple and keep using your System Events-based workaround to script Terminal’s GUI in the meantime.
Well, our first command we ran with do_script returned us a handle to the first tab of the window, surely we can get the window from that. Right? … Not so much. Time for a hack on a hack, and this one is just embarrassing. … Again, if someone knows the ??right?? way to do this, please let me know
If you dig down through appscript’s API layers you do eventually come to a visitor-style API that allows you to get at the innards of application references. However, it’s not publicly documented (info is available on request though) and not something I’d encourage- as you say, it’s really the application’s job to provide users with the info they need, and anything else is just a hack.
Since Cmd-T always creates the new tab in the frontmost window, personally I’d just wing it and use:
window_ref = app('Terminal').windows[1].get
By-index references aren’t as reliable as by-id reference since they tend to change according to stacking order, but if you send the above immediately after the tab is created (i.e. before anyone has a chance to bring another Terminal window frontmost) you should get a permanent by-id reference to the correct window back from Terminal:
app("/Applications/Utilities/Terminal.app").windows.ID(1159)
Unfortunately, while windows can be identified by unique id, it looks like tabs are still stuck with the by-index form, so if someone or something else creates a new tab in the same window later on I’m not quite sure how you’re meant to keep a reliable handle on your own tab. Though again this is a not uncommon dilemma when scripting applications, and I expect most folks just wing it here too, but feel free to file a feature request with Apple asking for Terminal tabs to support the by-id reference form in future releases.
HTH
has
—
http://appscript.sourceforge.net
http://rb-appscript.rubyforge.org
I’ve spent many hours discovering how to instant map my Korg microKONTROL to Ableton Live using the UserConfiguration.txt file, MidiPipe(optional), and the Librarian software that comes with the microKONTROL. I have successfully mapped the first 3 scenes of my microKONTROL to control various parameters in Live without having to Map them manually in midi map mode. The reason I made this tutorial is because I wish I could have had access for something like this. Would have saved me all the time it took to put this together. Good skills to learn though. No time was wasted. Before I walk you through how to set it up the way I did, let me show you how I configured the first three scenes. That way you’ll know how to use it once you download my templates.
Scene 1 Transport Controls (this one is the most complex)
To assign the scene up, scene down, and scene launch buttons, go into midi map mode, and under stop all clips in session view you will see play, up and down buttons. Those are to midi assign scene controls. Just click on the play arrow and press the scene launch on the keyboard, and the same with up and down.
Scene 2 Drum Rack Pads
Scene 3 Sends/Toggle Buttons
Here’s how to get your own Korg microKONTROL mapped like this on the Mac. (sorry PC users..) Step 1 If you have things mapped to the same midi messages already, it will override the instant mappings. So, before you try to achieve instant mapping, you will want to start a new live set and delete all midi and key mappings. Then go ahead and create 4 audio tracks, 4 midi tracks, and 2 returns as well. Place a drum rack on each midi track, and load up a kit for testing. Here is my Instant Mapping Template Project for Live 8 users. Step 2 Download my Custom Korg microKONTROL Preset, open it in the Librarian software, and transmit the scenes to your midi keyboard. Step 3 Download my UserConfiguration.txt file, and navigate to the following location on your Mac: (sorry again PC users..) User/Library/Preferences/Ableton/Live (YOUR VERSION)/User Remote Scripts Create a folder in User Remote Scripts and name it CustomicroKONTROL or whatever you want. Copy my UserConfiguration.txt file into the new folder. Step 4 Open Live’s preferences and go to the Midi Sync tab. Under Control Surface at the top, choose from the drop down CustomicroKontrol at the very bottom of the list most likely. (It will be called CustomicroKontrol even if you didn’t name the folder that as the name is chosen in the config file.) Now, close preferences. Step 5 Download and open MidiPipe freeware for Mac. Also, download my preset I made that converts midi into keystrokes using applescript, and open it in MidiPipe. You can also map the buttons yourself using midiStroke if you’d prefer. That’s it! If you did everything right, you should have all the functionality shown in my keyboard illustrations. If you want to customize your korg midi mapping, you can edit the UserConfiguration.txt file, and also setup your own applescript in MidiPipe to perform key commands or keystrokes if you so choose. The trick with MidiPipes is to click on the Alist then hit a button or adjust a control on the keyboard. Then, the applescript will bring Ableton to the front automatically. Just click back to MidiPipe and the CC# of the control will show up in the AList. You can then enter that number and the number of the keystroke you want to perform into the Applescript code. There is another freeware called Full Key Codes that will give you the key number of the apple keyboard key you press. It’s a bit tricky. You can look at my example, and hopefully that will help you. Good Luck! If you found this information useful, please make a donation to help support development of such materials. Every bit helps keep this site up and running. Thanks for all your support!!!





