Copy link to clipboard
Copied
I would like to see an alert window with the path to the original file.
A one line script:
Window.alert(app.activeDocument.fullName);
what I need is the first example
/user/username/folder
By @Ciccillotto
Try the following regular expression capture group addition:
require('photoshop').core.showAlert(app.activeDocument.path.replace(/(^.+\/)(.+)/, "$1"));
Copy link to clipboard
Copied
If you just want to know where the file is, right-click the document tab and choose Reveal In Finder/Explorer.
If you’re using macOS, you can also use the standard macOS shortcut of right-clicking the name in the title bar to reveal the full path to the document. This works only for a document floated as a window, because a tabbed document doesn’t display the standard macOS title bar.
Copy link to clipboard
Copied
A one line script:
Window.alert(app.activeDocument.fullName);
Copy link to clipboard
Copied
Thanks, just what I was looking for.
Copy link to clipboard
Copied
@Lumigraphics – I presume that is in the context of a UXP based panel? Do you know how to alert in a UXP .psjs context?
@Ciccillotto – Please make it clear when posting scripting questions if it is ExtendScript or UXP based, and if UXP – whether it should be for a stand-alone .psjs script or for use in a UXP panel.
Copy link to clipboard
Copied
Stefano, when I can't find documents on uxp, I try to find something on this forum, then if I'm lucky I can adapt it to uxp, but this is not always possible. said this, Stefano can you help me remove this symbol ~ at the beginning of the path. Unfortunately uxp doesn't recognize this character and blocks everything for me.
I don't need this for files. psjs, I need it for a uxp panel
Copy link to clipboard
Copied
Copy link to clipboard
Copied
when I start the script I get this string ~/user/user/username I would like to remove this symbol at the beginning ~
Copy link to clipboard
Copied
Hmmm...
The tildé symbol represents the relative path to the user folder.
In ExtendScript one can use a different construct:
app.activeDocument.path.fsName
And there are other possibilities as well, it's just a matter of getting them to work in UXP.
Otherwise, a JavaScript find/replace can remove the tildé symbol.
Copy link to clipboard
Copied
I'll take a look now Thank you
Copy link to clipboard
Copied
I have a feeling that plugin extension panels are very different to stand alone scripts when it comes to the file system.
Please post the relevant section of your code which returns the ~/user/user/username
Copy link to clipboard
Copied
Stefano I'm at work now I'll post screenshots as soon as I can.
Copy link to clipboard
Copied
Stefano I'm at work now I'll post screenshots as soon as I can.
By @Ciccillotto
You should just be able to use something like this:
require('photoshop').core.showAlert(app.activeDocument.path);
It appears that .fsName isn't supported in UXP.
Copy link to clipboard
Copied
fsName has been shown as deprecated in ExtendScript but some things wouldn't work without it. Hopefully Adobe has covered those holes.
Copy link to clipboard
Copied
Nope, that was just the code required for that particular output. It can be used is whatever manner from there. That does work as a stand-alone ExtendScript.
Copy link to clipboard
Copied
Nope, that was just the code required for that particular output. It can be used is whatever manner from there. That does work as a stand-alone ExtendScript.
By @Lumigraphics
Ah, OK...
For legacy Photoshop scripting, all one needs is the following bit in black:
Window.alert(app.activeDocument.fullName);
The preceding bit in bold-red isn't needed for Photoshop for the alert window to appear... So this is why I asked was it UXP code. I know you do a bit of Bridge scripting, is adding Window. required for that?
I am slowly trying to take the time to try to understand UXP, however, documentation is in it's infancy and there are differences between coding for panels and coding for stand-alone scripts.
I can't get an alert to work in a UXP based .psjs file! It doesn't get much simpler than "Hello World", but even that seems to be different in UXP!
EDIT: Ah, I found it!
require('photoshop').core.showAlert('Hello world!');
Or
const photoshop = require("photoshop");
const core = photoshop.core;
core.showAlert('Hello world!');
Copy link to clipboard
Copied
Actually it will work using just "alert" but this is not correct, the method documented by Adobe is Window.alert()
Copy link to clipboard
Copied
You're correct, I have seen it thousands of times as just alert, this is the first time that I recalll seeing the Window. prefix!
ExtendScript doesn't require app.activeDocument, one van drop app. and it also works, despite the DOM reference.
Curiously, UXP requires the app. prefix before activeDocument.
Go figure!
Copy link to clipboard
Copied
Congratulations, you've discovered that ExtendScript is buggy! :snark:
For Bridge 13/14, you get different results using the Window class rather than dropping it. I always just used alert() but that acts funny now. I took a look at UXP script (rather than writing a whole plugin) and it doesn't look terrible although they should either run Extendscript as-is or do an automated conversion. Also, I can't figure out if we are supposed to use the UXP app or VSCode (which I'm not a fan of on Mac) or exactly what.
Copy link to clipboard
Copied
Congratulations, you've discovered that ExtendScript is buggy! :snark:
Haha, yeah!
I took a look at UXP script (rather than writing a whole plugin) and it doesn't look terrible although they should either run Extendscript as-is or do an automated conversion.
I would be surprised if somebody doesn't create a script to massage ExtendScript into UXP. It would just take a few hundred/thousand find and replace routines! And even then, there will be syntax issues.
For example, activeDocument worked fine even though the textbook code stated the need to prefix the DOM app. prefix... However, in UXP, we have to include the parent DOM app.ActiveDocument for the code to execute.
Same for replacing var with let – before working out where a global const is required instead of let
Also, I can't figure out if we are supposed to use the UXP app or VSCode (which I'm not a fan of on Mac) or exactly what.
By @Lumigraphics
One can of course use any text app for the basic coding, but when it comes to integrated debugging using an IDE we have to use the new UXP Developer Tool.
One can get by without a UXP IDE, although it isn't ideal.
I believe that even for basic .psjs development, one must set up a "dummy" UXP panel environment to get the script to connect to Photoshop for debugging execution.
You aren't the only one who is struggling with this!
Copy link to clipboard
Copied
here I am
then the situation is this
this string is not good to fit uxp
Window.alert(app.activeDocument.fullName);
this is fine for me but not for uxp
Window.alert(app.activeDocument.path.fsName);
this one is fine for uxp but not for me
because it gives me the entire path plus the file name
app.activeDocument.path
what I need is the first example
/user/username/folder
Copy link to clipboard
Copied
I can't even figure out how to run a script. VSCode is useless, and the UXP Developer app gives me a plug in error.
Copy link to clipboard
Copied
what I need is the first example
/user/username/folder
By @Ciccillotto
Try the following regular expression capture group addition:
require('photoshop').core.showAlert(app.activeDocument.path.replace(/(^.+\/)(.+)/, "$1"));
Copy link to clipboard
Copied
that's fine
now I have to find a way to make it work with the uxp panel
Thank you Stefano