Hello,
I'm currently working on a Creative Suite Extension, which will show a collection of images on a panel (InDesign, Photoshop and Illustrator).
I need the application's path in a few javascript files and I'm getting weird problems on our testing-Mac. I have reduced the code to as few lines as possible, to show the problem.
Currently I'm using Photoshop CS5.1, Flash Builder 4.6 and Extension Builder 1.5 on my windows machine.
This is the code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
initialize="initializeHandler()">
<mx:Script>
<![CDATA[
import com.adobe.csawlib.photoshop.Photoshop;
import com.adobe.photoshop.*;
protected function initializeHandler():void
{
var app : com.adobe.photoshop.Application = com.adobe.csawlib.photoshop.Photoshop.app;
if(app.path)
myLabel.text = app.path.nativePath;
else
myLabel.text = "app.path was null";
}
]]>
</mx:Script>
<mx:VBox height="100%" width="100%" verticalAlign="middle" horizontalAlign="center">
<mx:Label id="myLabel"/>
</mx:VBox>
</mx:Application>
On my Windows machine myLabel shows the installation directory's path. On our Mac app.path is null, so it does not work.
I have tried many different approaches to solve this, but it doesn't work yet. Here are some ideas of what I tried so far:
- Get the path in Javascript instead using app.path.fsName (app.path is null on Mac in Javascript too, at least when it's called by the initialzeHandler)
- Put a timer in the initializeHandler, wait 10 seconds and try to get the path then (not a good idea and app.path is still null)
- Put a button on the panel that executes the initializeHandler instead. (app.path is working, but I need this to work without user interaction).
Can somebody enlighten me please?
Btw. I'm a developer trainee so it is likely that there is a simple solution or an obvious mistake, feel free to point them out.
Hi,
for what is worth, with Extension Builder 2.0 (Flash Builder 4.5.1) on OSX Lion, the following works:
package
{
import com.adobe.csawlib.photoshop.Photoshop;
import com.adobe.photoshop.*;
public class ZPhotoshop
{
public static function run():void
{
var app:Application = Photoshop.app;
if(app.path) {
trace("App path is: " + app.path.nativePath);
} else {
trace("null path");
}
}
}
}
(this is in the .as file that EB creates by default)
The result is:
App path is: /Applications/Adobe Photoshop CS6
Regards,
Davide
Hi,
I can not get the path on initialize or creationComplete, if I wait for a user interaction it works.
Do you call the run method on initialize or by the default button click?
I have tried your Code and it works on button click in Mac OS only.
Updating to Extension Builder 2 right now. Maybe that will help.
Hi,
we installed Extension Builder 2.0, rebuilt our testcase and tried again. It still doesn't work.
Some additional Info:
Testing machines:
Mac OSX Lion - Photoshop CS5 - 64Bit // not running
Mac OSX Snow Leopard - Photoshop CS5 - 64Bit // not running
Max OSX Snow Leopard - Photoshop CS5 - 32Bit // not running
Windows XP SP3 - Photoshop CS5.1 - 32Bit // running smooth
Built on:
Windows XP SP3 - FlashBuilder 4.6 - ExtensionBuilder 2.0
Mac OSX Snow Leopard - Flash Builder 4 - ExtensionBuilder 1.5
We can not call app.path from the initialize or creationComplete event on Mac. It is null in that moment.
We can call app.path from a button Handler.
Code:
test.mxml:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
historyManagementEnabled="false"
applicationComplete="colorSync()"
>
<mx:Script>
<![CDATA[
[Bindable]
private var hostName:String = HostObject.mainExtension;
public function colorSync():void{
AutoTheme.sync();
testPhotoshop.run();
}
]]>
</mx:Script>
<mx:VBox height="100%" width="100%" verticalAlign="middle" horizontalAlign="center">
<mx:Button label="Run PS code" click="testPhotoshop.run()" enabled="{hostName.indexOf('photoshop') > -1}"/>
<mx:Label id="myLabel"
text="has not been set yet"/>
</mx:VBox>
</mx:Application>
testPhotoshop.as:
package
{
import com.adobe.csawlib.photoshop.Photoshop;
import com.adobe.photoshop.*;
import mx.core.Application;
public class testPhotoshop
{
public static function run():void
{
var app: com.adobe.photoshop.Application = Photoshop.app;
if(app.path)
mx.core.Application.application.myLabel.text = app.path.nativePath;
else
mx.core.Application.application.myLabel.text = "app.path was null";
}
}
}
We still need this to work without user interaction.
Thank you for your help so far DBarranca.
Regards
Kevin
Thanks for the tip, I tried the following. This works fine on the Windows machine, but on Mac I still get errors.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
historyManagementEnabled="false"
applicationComplete="applicationCompleteHandler()"
>
<mx:Script>
<![CDATA[
[Bindable]
private var hostName:String = HostObject.mainExtension;
private var timer : Timer = new Timer(5000,1);
public function applicationCompleteHandler():void{
AutoTheme.sync();
timer.addEventListener(TimerEvent.TIMER, timerCompleteHandler);
timer.start();
try{
var jsxInterface : HostObject = HostObject.getRoot(HostObject.extensions[0]);
var jsGetPathFunc : String = " function getAppPath(){ try { return app.path.fsName; } catch (e){return 'JS Error: ' + e;} } ";
jsxInterface.eval(jsGetPathFunc);
myLabel2.text = jsxInterface.getAppPath();
} catch (e : Error) {
myLabel2.text = "Error while calling JS: " + e.getStackTrace();
}
}
private function timerCompleteHandler(event : Event) : void{
testPhotoshop.run();
}
]]>
</mx:Script>
<mx:VBox height="100%" width="100%" verticalAlign="middle" horizontalAlign="center">
<mx:Button label="Run PS code" click="testPhotoshop.run()" enabled="{hostName.indexOf('photoshop') > -1}"/>
<mx:Label id="myLabel"
text="has not been set yet"/>
<mx:Label id="myLabel2"
text="has not been set yet"/>
</mx:VBox>
</mx:Application>
On Mac.
- MyLabel shows "app.path was null", after 5 seconds. When I click the button to call for testPhotoshop.run() manually, it shows the application's path (means it's working in general, just not at the event).
- MyLabel2 shows a JS-Error. I'm using a german Photoshop, so the error I'm getting is in german as well. It translates roughly into this: JS-Error: "I/O-Error: General Photoshop Error. The function may not be availible in this version of Photoshop."
I took a closer look at the javascript objects and app.path is null in javascript as well, at least when called from the applicationCompletehandler.
Any advice?
Btw. I know that the code looks strange, keep in mind that it is for testing purposes only.
These threads might help:
http://forums.adobe.com/message/2983515#2983515
http://forums.adobe.com/message/3041081#3041081
And read this Cookbook entry:
http://cookbooks.adobe.com/post_Creative_Suite_Extensions_and_the_Phot oshop_CS5_Re-17727.html
Harbs
Harbs,
the cookbook hit the nail on the head. Thanks a lot. It is working now.
http://cookbooks.adobe.com/post_Creative_Suite_Extensions_and_the_Phot oshop_CS5_Re-17727.html
Barranca,
the last example was built with ExtensionBuilder 2.0.
Working code for anyone with a similar problem:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
applicationComplete="dummyHandler(event)">
<mx:Script>
<![CDATA[
import com.adobe.csawlib.photoshop.Photoshop;
import com.adobe.devtech.PsEventScrubber;
import com.adobe.photoshop.Application;
private function dummyHandler(event : Event) : void{
PsEventScrubber.getInstance().scrubEvent(event, realHandler);
}
private function realHandler(event : Event) : void{
var app : com.adobe.photoshop.Application = com.adobe.csawlib.photoshop.Photoshop.app;
myLabel.text = app.path.nativePath;
}
]]>
</mx:Script>
<mx:VBox height="100%" width="100%" verticalAlign="middle" horizontalAlign="center">
<mx:Label id="myLabel"/>
</mx:VBox>
</mx:Application>
You need to include the library from the cookbook and then this works on Macs as well.
Thanks again. This would have taken me a week or more to figure out.
North America
Europe, Middle East and Africa
Asia Pacific