Page 1 of 1

convert applescript help

PostPosted: Thu Apr 30, 2020 6:43 pm
by farberm
Does this conversion look correct:

I will store api key variable in apikey

http link to file location is: http://192.168.2.22:3006/render/d-solo/ ... d?orgId=1& panelId=26&width=1000&height=500&tz=America%2FNew_York

apple script needed to convert:
Code: Select all
do shell script "curl -o \”/Library/Application Support/Perceptive Automation/Indigo 7/IndigoWebServer/images/image.jpg>” -H \"Authorization: <APIKEY>\” \"http://<INSERT LINK TO DIRECT LINK RENDERED IMAGE>\””

potential script:
Code: Select all
import os
apiKey = indigo.variables["variable name whereI store the api key"].value
os.system("/usr/bin/curl -f 'http://192.168.2.22:3006/render/d-solo/xF85NDZiz/indigo-home-dashboard?orgId=1& panelId=26&width=1000&height=500&tz=America%2FNew_York
&apiKey='"+apiKey+"' -o \”/Library/Application Support/Perceptive Automation/Indigo 7/IndigoWebServer/images/image.jpg")

Re: convert applescript help

PostPosted: Fri May 01, 2020 10:01 am
by jay (support)
This is what I'd do (based on your AppleScript, not your conversion attempt):

Code: Select all
import requests

# Set up the variable data
url = "http://<INSERT LINK TO DIRECT LINK RENDERED IMAGE>"
file_name = "{}/IndigoWebServer/images/image.jpg".format(indigo.server.getInstallFolderPath())
api_key = indigo.variables[123456789].value
auth_header = {"Authorization": api_key}

# Use the requests library to fetch the file
reply = requests.get(url, headers=auth_header)

# If it got a good reply
if reply.status_code == 200:
    # Open the output file
    with open(file_name, 'wb') as output_file:
        # Write out the image data to the file
        output_file.write(reply.content)


Note that your attempt might (or might not) work - but spawning yet another process to do the curl command is unnecessary overhead since you can do it directly in Python instead.

[MODERATOR NOTE]: I deleted your other duplicate post and updated the script to include getting the API key from an Indigo variable. Please don't post duplicate posts as it will just cause confusion.

Re: convert applescript help

PostPosted: Mon May 11, 2020 3:48 pm
by farberm
Jay thanks for your help.

I tested the script but it does not seem to generate a image.jpg in the folder Indigowebserver/Images folder

I checked the http link that I inserted and it works when I paste it into a web browser.

Do I need to change the file_name location to be exact.

file_name = " Library/Application Support/Perceptive Automation/IndigoWebServer/images/image.jpg" or is that already implied with the. .format(indigo.server.......())

I did not see anything in the log file so not sure how to debug the issue?

Thanks again for your help.

Re: convert applescript help

PostPosted: Mon May 11, 2020 6:02 pm
by FlyingDiver
farberm wrote:
Jay thanks for your help.

I tested the script but it does not seem to generate a image.jpg in the folder Indigowebserver/Images folder

I checked the http link that I inserted and it works when I paste it into a web browser.

Do I need to change the file_name location to be exact.

file_name = " Library/Application Support/Perceptive Automation/IndigoWebServer/images/image.jpg" or is that already implied with the. .format(indigo.server.......())

I did not see anything in the log file so not sure how to debug the issue?

Thanks again for your help.


Code: Select all
file_name = "/Library/Application Support/Perceptive Automation/IndigoWebServer/images/image.jpg"


You need the leading slash for that path to work.

Re: convert applescript help

PostPosted: Wed May 13, 2020 2:22 pm
by jay (support)
farberm wrote:
Jay thanks for your help.

I tested the script but it does not seem to generate a image.jpg in the folder Indigowebserver/Images folder

I checked the http link that I inserted and it works when I paste it into a web browser.

Do I need to change the file_name location to be exact.

file_name = " Library/Application Support/Perceptive Automation/IndigoWebServer/images/image.jpg" or is that already implied with the. .format(indigo.server.......())

I did not see anything in the log file so not sure how to debug the issue?

Thanks again for your help.


As Joe pointed out, if you are going to specify the path yourself, it should start with a slash. However, my script avoids hard coding the path so that it will work with any Indigo 7 release. Are you sure you copied the script EXACTLY? If you paste it into an Execute Script action then press the Run button, doe it show any errors? Did you substitute the correct URL and the correct ID for the variable?

Re: convert applescript help

PostPosted: Wed May 13, 2020 2:27 pm
by farberm
Thanks. I am working on some changes to make it work. I think i have it now. One additional question. It look like it takes several seconds to create the file. I am running this script on a control page to generate an image for it. What is the best way to make it update in either of thes two fashions:

1. When I access the control page
or

2. Once an hour.

Is this done thru creating a schedule?

Re: convert applescript help

PostPosted: Wed May 13, 2020 3:59 pm
by jay (support)
Running a schedule to do it is definitely the straight-forward way.

There isn't a trigger that would execute the script when a control page loads, so you'd need to click/tap something to get the image to update.