Friday, December 15, 2017

#1 2017-01-19 11:43:29 am

sancarn
Member
Registered: 2017-01-16
Posts: 7

Extending the UI of an existing application.

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:

Applescript:

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!)

Thanks,
~Sancarn

Last edited by sancarn (2017-01-19 11:44:43 am)


Filed under: Button, UI, add, Extend

Offline

 

#2 2017-01-19 06:00:30 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5199

Re: Extending the UI of an existing application.

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.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#3 2017-01-20 03:00:25 am

sancarn
Member
Registered: 2017-01-16
Posts: 7

Re: Extending the UI of an existing application.

Shane Stanley wrote:

But unless you own the window, it's not going to work.


Gosh darn it! I was hoping you could get the window from the processes class:

Applescript:

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?

Shane Stanley wrote:

I'm rusty on JXA


That's fine, If I can get my hands on some AS code I can hopefully port it smile

Offline

 

#4 2017-01-20 06:16:54 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5199

Re: Extending the UI of an existing application.

sancarn wrote:

perhaps you can inject menu items into other applications with ASObjC/JXA?


I hope not. It would be a massive security hole.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#5 2017-01-20 04:47:53 pm

sancarn
Member
Registered: 2017-01-16
Posts: 7

Re: Extending the UI of an existing application.

Shane Stanley wrote:
sancarn wrote:

perhaps you can inject menu items into other applications with ASObjC/JXA?


I hope not. It would be a massive security hole.


I'm not entirely sure why it would be a security issue? As far as I am aware, software developers shouldn't have to concern themselves with security... An applescript by itself is a security risk after all...

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)

Anyway:

Extending the UI of finder can be seen here:
https://pmougin.wordpress.com/2009/10/2 … plication/

F-Script Anywhere:
https://github.com/adamnemecek/FScriptAnywhere

F-Script framework:
https://github.com/Kentzo/F-Script/releases

Last edited by sancarn (2017-01-20 04:48:33 pm)

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)