• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
2

File path loaded into photoshop

Engaged ,
Feb 12, 2024 Feb 12, 2024

Copy link to clipboard

Copied

I would like to see an alert window with the path to the original file.

 

TOPICS
Actions and scripting

Views

360

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

LEGEND , Feb 12, 2024 Feb 12, 2024

A one line script:

Window.alert(app.activeDocument.fullName);

Votes

Translate

Translate
Community Expert , Feb 13, 2024 Feb 13, 2024
quote

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"));

 

 

Votes

Translate

Translate
Adobe
Community Expert ,
Feb 12, 2024 Feb 12, 2024

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 12, 2024 Feb 12, 2024

Copy link to clipboard

Copied

A one line script:

Window.alert(app.activeDocument.fullName);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 12, 2024 Feb 12, 2024

Copy link to clipboard

Copied

Thanks, just what I was looking for.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 12, 2024 Feb 12, 2024

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 12, 2024 Feb 12, 2024

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 12, 2024 Feb 12, 2024

Copy link to clipboard

Copied

@Ciccillotto 

 

I don't see the example?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 12, 2024 Feb 12, 2024

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 ~

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 12, 2024 Feb 12, 2024

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 13, 2024 Feb 13, 2024

Copy link to clipboard

Copied

I'll take a look now Thank you

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 13, 2024 Feb 13, 2024

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 13, 2024 Feb 13, 2024

Copy link to clipboard

Copied

Stefano I'm at work now I'll post screenshots as soon as I can.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 13, 2024 Feb 13, 2024

Copy link to clipboard

Copied

quote

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 13, 2024 Feb 13, 2024

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 13, 2024 Feb 13, 2024

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 13, 2024 Feb 13, 2024

Copy link to clipboard

Copied

quote

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!');

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 13, 2024 Feb 13, 2024

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()

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 13, 2024 Feb 13, 2024

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 13, 2024 Feb 13, 2024

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 13, 2024 Feb 13, 2024

Copy link to clipboard

Copied

LATEST
quote

Congratulations, you've discovered that ExtendScript is buggy! :snark:

 

Haha, yeah!

 

quote

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

 

quote

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!

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 13, 2024 Feb 13, 2024

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);

1ok.png

this one is fine for uxp but not for me
because it gives me the entire path plus the file name
app.activeDocument.path

2ok.png

what I need is the first example
/user/username/folder

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 13, 2024 Feb 13, 2024

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 13, 2024 Feb 13, 2024

Copy link to clipboard

Copied

quote

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"));

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 13, 2024 Feb 13, 2024

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

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines