2014-11-01 48 views
-3

我通過Javascript腳本的Photoshop的基本思想API集成..用Photoshop

我想在我的Photoshop腳本http://www.wunderground.com(API)的使用數據。

但不知道如何請求(訪問)這些數據。

任何人都可以指導我如何去做。

問候

+0

你有沒有嘗試過任何你自己呢? – 2014-11-01 14:08:54

回答

0

我可以做這種事情,但我不知道它是多麼笨拙的 - 有可能是一個更簡單的方法,我不知道 - 所以我們會看到是否有人想出更好的東西。

首先,尋找到你的PHP的位置,這樣的:

which php 
/usr/local/bin/php 

讓我看到我的是在/usr/local/bin/php。我需要爲我的PHP腳本的第一行。

現在創建一個訪問Wunderground API的獨立PHP腳本。我沒有鑰匙,所以我實際上沒有調用他們的API,而是將這些調用註釋掉,然後僞造結果。所以,我這個保存爲/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"; 
?> 

我作出這樣的可執行文件是這樣的:

chmod +x /Users/Mark/tmp/wunderground.php 

像這樣運行:

/Users/Mark/tmp/wunderground.php 
Current temperature is 36 

你懶得做其他事情之前,這一步必須工作,所以我在這裏獨立測試......看起來不錯!

現在我寫一個Photoshop的ActionScript/JavaScript的啄並將其保存爲<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); 

您將看到第二行執行PHP腳本,並將結果保存在一個文件,然後我讀取並顯示內容在alert()

所以,我重新啓動Photoshop,因爲編輯我的腳本(只在啓動時分析它們),然後我去在Photoshop中File->Scripts和chosse Test.jsx

下面是它的外觀:

enter image description here