I would appreciate if the response was in JXA, but Applescript would at least give me an idea of what calls I need to make.
I have already seen some examples of creating buttons with windows:
So I would assume my code would be something like this:
ObjC.import("Cocoa");
//If no superclass is provided, NSObject is subclassed.
ObjC.registerSubclass({
name:"AppDelegate",
methods:{
"btnClickHandler:":{
types:["void",["id"]],
implementation:function(sender){
//My button implementation
}
}
}
});
var window=Application('Some Application').window[0]
var appDelegate=$.AppDelegate.alloc.init;
var btn=$.NSButton.alloc.initWithFrame($.NSMakeRect(25,(height-100),200,25));
btn.title="Run JXA";
btn.bezelStyle=$.NSRoundedBezelStyle;
btn.buttonType=$.NSMomentaryLightButton;
//NOTE:See NSButton docs for info on target/action
btn.target=appDelegate;
btn.action="btnClickHandler:";
btn.keyEquivalent="\r"; //Enterkey
window.contentView.addSubview(btn);
However I have very little experience with Applescript or Objective C, so am wondering whether I am on the right track (or even if what I’m trying to do is possible!)
I’m rusty on JXA, and I’m not sure where you’re getting your window from. But unless you own the window, it’s not going to work. I doubt that you need the AppDelegate stuff – the main thing is to make the script the target of the button.
Gosh darn it! I was hoping you could get the window from the processes class:
Processes('ScreenFlow').windows[0]
If I need to own the window… I guess the only option would be to have an invisible window made in AS with visible UI elements which tracks the size of the window (and controls) of the other application?
Hmm… I also remember that F-Script, after being injected into applications, created it’s own menu item, so perhaps you can inject menu items into other applications with ASObjC/JXA?
That’s fine, If I can get my hands on some AS code I can hopefully port it
Surely it would be nothing but a good thing for scripters? One of the most important things, in my mind, when developing scripts is to make them easy for users to use… Adding menu items for instance is a great way to achieve this - equivalently adding window elements.
It’s one of the reasons why I love HTML/JS. Because it’s easy to take someones website and just add features to it… (With JS script injection I mean)