Copy link to clipboard
Copied
Hello there! I'm pretty new to this whole coding/scripting thing, so forgive me...
I'm trying to pass a variable to get the relative path to a .jsx file via bridgetalk (From Illustrator to Photoshop if that is of any matter!)
Here's my code:
1 Correct answer
one way of doing what you need with minimal changes to your code is by
- wrapping your psScript in a function
- adding the function call to your bt.body. In other words, right now message refers to the psScript (which is just the function now), so we need to add the function call including the path parameter.
function main() {
var scriptPath = (new File($.fileName)).path
//Bridgetalk stuff
var scriptToLoad = new File (scriptPath + "/psScript.jsx") // laddar den rätta skriptfile
...
Explore related tutorials & articles
Copy link to clipboard
Copied
one way of doing what you need with minimal changes to your code is by
- wrapping your psScript in a function
- adding the function call to your bt.body. In other words, right now message refers to the psScript (which is just the function now), so we need to add the function call including the path parameter.
function main() {
var scriptPath = (new File($.fileName)).path
//Bridgetalk stuff
var scriptToLoad = new File (scriptPath + "/psScript.jsx") // laddar den rätta skriptfilen
try {
if (!scriptToLoad.exists) { throw new Error("script not found!"); }
scriptToLoad.open ("r"); // read only
var message = scriptToLoad.read();
scriptToLoad.close()
} catch (error) {
alert("Error parsing the file: " + error.description);
}
//#target photoshop-13
var bt = new BridgeTalk();
bt.target = "photoshop";
bt.body = message + "\nreadPath('" + scriptPath + "')";
bt.send();
//And on the other end in psScript.jsx I'm just trying to get it to alert me the path in a dialog box:
//function readPath(scriptPath) {
// alert('Script path is: ' + scriptPath);
//}
}
main();
Copy link to clipboard
Copied
A thousand thanks mate, this helped! 🙂
Copy link to clipboard
Copied
@CarlosCanto
Do you happen to know if $.fileName works on newer OSX machines? Im working on a script and a user is telling me, ($.fileName) or any alternative method for this always returns `undefined`.
I find this very strange. He is using OSX 12.7
Copy link to clipboard
Copied
@schroef I'm on Windows, I'm unable to test on Mac
Copy link to clipboard
Copied
@CarlosCanto Ah i see, thanks
Copy link to clipboard
Copied
$.fileName still works on macOS Monterey 12.6.7. Maybe a permissions problem on the system?
Copy link to clipboard
Copied
Thanks for the headsup. I think the person doing the test also came to this conclusion. I can only test a machine running 10.11.6
Can we lift that by doing CMD+i and than add permissions to that folder for the current user?
The scrript needs to write and read a json file which is next to the AI file. So i find it perhaps its weird that it has no permissions, when Illustrator can easily write the AI file.
Copy link to clipboard
Copied
Does reading the document path work on his machine? activeDocument.path, activeDocument.fullName, activeDocument.fullName.fsName and something like that? Or is the problem just returning the JS file path?
Copy link to clipboard
Copied
Well your solution is actually what this user wanted. He wants to have a preset file saved aside of the open document as each document is different.
My approach was to use a single method, because otherwise it will reset to default in the initial run.
Ill pass this through to him, hope it works
Copy link to clipboard
Copied
@Sergey Osokin Actually it is not working on my side with Monterey 12.7.1. ... and I don't know why.
I checked it with app.path and set a path in the script, to create and store a prefs-file at the location of the script and it worked. So it does not deal with permissions.
But $.fileName of the script, will only throw an empty field and a slash fot the path or wrong type ...?
Any idea on that issue?
Best
Copy link to clipboard
Copied
It seems you are on 12.6.7
Would you be able to test this alert for me? The user said on his system a simple alert($.fileName) doesnt work
alert(File($.fileName).path;
The issue is about this script > getShapeAreaDialog an script which returns the area of (a) shape(s) and store the settings in a json sidefile.
For him the loading section and saving doesnt seem to work and keeps returning UNDEFINED
Copy link to clipboard
Copied
macOS 12.6.7
alert( $.fileName ) —> /Users/serg/Downloads/test.jsx
alert( File($.fileName) ) —> ~/Downloads/test.jsx
alert( (File($.fileName)).path ) —> ~/Downloads
Copy link to clipboard
Copied
@Sergey Osokin @schroef it would be interesting for the script path, in programm folder in Scripting
Copy link to clipboard
Copied
$.fileName > /Applications/Adobe Illustrator 2024/Presets.localized/en_GB/Scripts/<script_name>
File($.fileName) > /Applications/Adobe%20Illustrator%202024/Presets.localized/en_GB/<script_name>
(File($.fileName)).path > /Applications/Adobe%20Illustrator%202024/Presets.localized/en_GB/Scripts/<script_name>
I have already upgraded my system to macOS 12.7.2 and I still have no problem returning the path via $.fileName.
Copy link to clipboard
Copied
One issue i see. The folder is never called '/Presets.localized'. This will throw an error. Ive seen this before where i needed to add hardcoded part. The folder is called 'Presets" in english, but in a different language its different. I believe this is a OSX thing. On Windows alert($.fileName).path, does not return the .localized in the path. Thats interesting. Actually, i just noticed first it alerts the path and than an error Undefined is not an object; line 1. When i do: alert(File($.fileName).path), it also returns the path but without the error.
But when i do
No error is given, very strange behavior
Copy link to clipboard
Copied
I checked it on my Laptop, now, too.
It does not work there either. I'm absolutely clueless what the root cause of this issue is ...
I get only
/3
/3
Empty field
or undefined ...
Copy link to clipboard
Copied
Well when i added alert(File($.fileName).path) then i did not get the error.
I think the trailing .path on the alert gives an error because it is outside the alert, yet on the first actually alert it does work. Its weird from ExtendScript's side.
@Someone75
from where are you calling that script?
I did a test placing a test.jsx inside the Applications/Adobe/Illustrator blablablab. Im on windows so path is a but different
Copy link to clipboard
Copied
I gave Illustrator complete privileges to the whole hard disk. Not change to get the folder path ...
The script is stored inside the scripts preset folder.
Copy link to clipboard
Copied
... inside Applications:/Applications/Adobe Illustrator 2024/Presets.localized/de_DE/Skripten/GetShapeArea-dialog.jsx
Copy link to clipboard
Copied
So it seems because @Someone75 was using a dedicated acriptpanel to run the script, the $.fileName was being suppressed or something. Nice detail to know.
Makes me want to check out that panel and see whats going Ng on in the backend and why or how it's suppressing $.fileName

