I have a basic idea of Photoshop scripting via Javascript..
I want to use data from http://www.wunderground.com (Api) in my photoshop script.
But have no idea how to request(access) these data.
I have a basic idea of Photoshop scripting via Javascript..
I want to use data from http://www.wunderground.com (Api) in my photoshop script.
But have no idea how to request(access) these data.
I can do that sort of thing, but I am not sure how clunky it is - there could be an easier way I don't know - so we'll see if anyone else come up with something better.
First, find where your PHP is located, like this:
which php
/usr/local/bin/php
so I see mine is in /usr/local/bin/php
. I need that for the first line of my PHP script.
Now make a stand-alone PHP script that accesses Wunderground's API. I do not have a key, so I have not actually called their API, rather I have commented out the calls and then faked the results. So I save this as /Users/Mark/tmp/wunderground.php
#!/usr/local/bin/php
<?php
// $json_string = file_get_contents("http://api.wunderground.com/api/Your_Key/geolookup/conditions/q/IA/Cedar_Rapids.json");
// $parsed_json = json_decode($json_string);
// $location = $parsed_json->{'location'}->{'city'};
// $temp_f = $parsed_json->{'current_observation'}->{'temp_f'};
// echo "Current temperature in ${location} is: ${temp_f}\n";
echo "Current temperature in 36";
?>
I make that executable like this:
chmod +x /Users/Mark/tmp/wunderground.php
and run it like this:
/Users/Mark/tmp/wunderground.php
Current temperature is 36
This step MUST work before you bother doing anything else, and so I test it stand-alone here... looks good!
Now I write a Photoshop Actionscript/Javascript thingy and save it as <Photoshop>/Presets/Scripts/Test.jsx
alert("Hello world!")
app.system("/Users/Mark/tmp/wunderground.php > /Users/Mark/result.txt")
var w = new File("/Users/Mark/result.txt");
w.open('r');
var str = "";
while(!w.eof)
str += w.readln();
w.close();
alert(str);
You see that executes the PHP
script on the second line and saves the result in a file which I then read and display the contents of in an alert()
.
So, I re-start Photoshop since editing my script (it only parses them at startup) and then I go in Photoshop to File->Scripts
and chosse Test.jsx
Here is how it looks: