Copy link to clipboard
Copied
I am working on a Photoshop script that writes data to txt file.
In the following folder structure example:
Summer Collection
June
Peaches
var pName = outputFolder.name writes Peaches to the txt file.
var mName = outputFolder.parent.name writes June to the txt file.
How can I define a variable that writes Summer Collection to the txt file and excludes the empty space %20 symbol?
Hope the question is clear. Let me know if you need additional details to clarify the question.
pName = path.name, mName = name;
(txt = File(Folder.desktop + '/txt.txt')).open('w')
txt.write(decodeURI(pName) + '/' + decodeURI(mName)), txt.close()
This works well when the directory name is WIP. Is it possible to make the WIP variable so that independently from the name the code can get the name of the folder two levels up?
activeDocument.path.parent.parent.name
Copy link to clipboard
Copied
pName = path.name, mName = name;
(txt = File(Folder.desktop + '/txt.txt')).open('w')
txt.write(decodeURI(pName) + '/' + decodeURI(mName)), txt.close()
Copy link to clipboard
Copied
The code writes Adobe Photoshop 2021/Adobe Photoshop to the tx.txt file on the desktop.
While the open psd doc is locatedUser/Desktop/stack test/photoshopdoc.psd
Not sure why the name is automatically crossed over.
Should the script write User/Desktop to the txt.txt file on the desktop?
Copy link to clipboard
Copied
Each time you launch Photoshop, its name is automatically beeing assigned to variable, for example it is same for path). txt.txt is saved to desktop as seen in the code as I'm not mind-reader to know where you'd like it to be saved 😉 There is nothing about it in your original post so txt should be saved on desktop 🙂 path and name are used instead of outputFolder.
Copy link to clipboard
Copied
Thank you for clarifying. I am trying to write the directory WK22 only to a txt file when the script runs on a file that is located in the WIP directory. Is that possible and does it make sense?
/Users/Shared/PHOTO/WIN/POST/2021/06 JUNE/WK22/GNO/WIP
Copy link to clipboard
Copied
Which bit are you having issues with?
Triggering the write if the file is located in the WIP directory?
Or manipulating the text string to only write WK22?
Copy link to clipboard
Copied
In the folder path sample, I can write the directory WIP and GNO to the txt file. I am having difficulty writing the directory WK22 to the file. The text file should look like this:
WK22, GNO, WIP
Copy link to clipboard
Copied
if ((nme = (pth = activeDocument.path).name) == 'WIP')
alert([(prnt = pth.parent).parent.name, prnt.name, nme])
Copy link to clipboard
Copied
if ((pth = activeDocument.path).name == 'WIP') alert(pth.parent.parent.name)
Copy link to clipboard
Copied
This works well when the directory name is WIP. Is it possible to make the WIP variable so that independently from the name the code can get the name of the folder two levels up?
Copy link to clipboard
Copied
activeDocument.path.parent.parent.name
Copy link to clipboard
Copied
probably because
path == app.path
name == app.name
and cannot be changed
Copy link to clipboard
Copied
delete name; name = 'I\'m changed', alert(name), name = app.name, alert(name)
Copy link to clipboard
Copied
well, wow
Copy link to clipboard
Copied
Thank you that works for me!
Copy link to clipboard
Copied
As I learnt regular expressions before scripting, my go to would be:
yourVariable.name.replace(/%20/g, ' ');
I'll try to keep the decodeURI in mind as I have seen this elsewhere, thanks Kukurykus!
Copy link to clipboard
Copied
File.decode('/%20/')
Copy link to clipboard
Copied
this gr8