[ANSWERED] applescript from web server control pages

Posted on
Wed Mar 12, 2014 6:57 am
mat offline
Posts: 769
Joined: Nov 25, 2010
Location: Cambridgeshire - UK

[ANSWERED] applescript from web server control pages

Morning,

I've set up some revised control pages for tv control.

One button executes a client action to change the control page from "freesat" to "freeview" (to reflect different available channels) then completes a client action to execute some apple script to send the appropriate ir to change the tv input.

All works on iso.

However, when running from the web server, the control page is changed first (using client action - open control page) but the applescript isn't run. It does work if a new tab is open, but I want to avoid loads of tabs in safari.

Is the client action executed before the server action, thus the server action never executes as a new page has been loaded in the same tab? If so, can the priority be changed, i.e. execute the server actions (for the applescript) before executing the client action (to change the url)?

Can I open control page (in the same tab) from applescript to avoid using the server action, thus controlling the order in which the commands are executed? I'm not sure that would then work on iOS though would it?

I can't see any other posts on the subject.

Cheers


Mat
Last edited by mat on Wed Mar 12, 2014 7:12 am, edited 1 time in total.

Late 2018 mini 10.14

Posted on
Wed Mar 12, 2014 7:10 am
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

Re: applescript from web server control pages

Hi Mat,

The issue is that Safari shuts down the Javascript for the original page (because it is loading the URL to the new page) before it has time to send the command to the IndigoServer. I believe this problem may be specific to Safari. I know Indigo Touch finishes sending the server command, as I believe FireFox did (when I tested it years ago). That was before Chrome, so I'm not sure what it does off the top of my head. There is no way from a server action or AppleScript to redirect Safari to a new Control Pages -- that has to occur on the browser/HTML/JS side. I believe there are a couple of ways we can fix this, so I'll make sure it is on our bug list. None of the fixes are trivial though, so no ETA on it...

Image

Posted on
Wed Mar 12, 2014 7:15 am
mat offline
Posts: 769
Joined: Nov 25, 2010
Location: Cambridgeshire - UK

Re: applescript from web server control pages

Thanks Matt. I stopped using crome for indigo as the pages didn't appear to render correctly - I have OCD :0 and not all of the controls lined up perfectly. It may have been because I was zooming though.

I'll have a think about it :)

Late 2018 mini 10.14

Posted on
Wed Mar 12, 2014 7:47 am
mat offline
Posts: 769
Joined: Nov 25, 2010
Location: Cambridgeshire - UK

Re: applescript from web server control pages

Almost resolved a work around….

the following script works, but not if safari is in full screen

Code: Select all
tell application "Safari"
   
   set winlist to count of every window
   repeat with i from 1 to winlist
      close (every tab of window i whose name = "INDIGO HOME CONTROL SERVER : TV CONTROL - FREESAT")
   end repeat
end tell

Late 2018 mini 10.14

Posted on
Wed Mar 12, 2014 8:31 am
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

Re: applescript from web server control pages

That approach could work, but note it will only apply to the Mac running Safari that is also running the Indigo Server process since that is where the AppleScript will be executing.

Image

Posted on
Wed Mar 12, 2014 10:54 am
mat offline
Posts: 769
Joined: Nov 25, 2010
Location: Cambridgeshire - UK

Re: applescript from web server control pages

Damn. Didn't think of that, your one step ahead as usual - thanks Matt - and I had just resolved the full screen issue I think :)

As I only use my MBP to access the web server (it sits on the coffee table constantly), I'll look at a way of activating a remote applescript or similar (from the indigo server mini) on the MBP. Not sure its possible, but will explore - it may have some useful side effects of keeping the MBP up-to date with the correct control page as the ipads too. Here's hoping in my naivety.

I'll post any results.

Mat

Late 2018 mini 10.14

Posted on
Wed Mar 12, 2014 12:42 pm
RogueProeliator offline
User avatar
Posts: 2501
Joined: Nov 13, 2012
Location: Baton Rouge, LA

Re: applescript from web server control pages

Mat:

I am pretty sure you can create an AppleScript saved as an application bundle to do what you are wanting... the key would be to edit the info.plist file to add a key that has a CFBundleIdentifier to identify the script and then a CFBundleURLTypes node that defines a URL scheme that the script will listen for (just has to be unique in the system, like "matshelper").

Your script will need an "on open location the_clicked_url" handler that receives the URL.

Then that SHOULD be called whenever a link in your control page starts with that URL...
matshelper://[uniqueidentifierhere]?param1=value1&param2=value2

The parameters can be used to tell the script what to do so that you only need one script to handle multiple actions... but you don't technically have to use them. Note that this is totally untested, but should work as that is basically how it works for normal (non-applescript) applications to the best of my recollection. Maybe, at the least, it could give you a starting point to try...

Adam

Posted on
Sat Mar 15, 2014 4:00 am
mat offline
Posts: 769
Joined: Nov 25, 2010
Location: Cambridgeshire - UK

Re: applescript from web server control pages

Thanks Adam,

I'll look into your idea. It's all double dutch to me at the moment, but looks like a good research and learning project to take my scripting to another level :)

I'll let you know how I get on.

Thanks again,

Mat

Late 2018 mini 10.14

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 2 guests