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

Return results of AppleScript (or Shell command) called from Illustrator ExtendScript

Participant ,
Jun 23, 2024 Jun 23, 2024

Copy link to clipboard

Copied

I'm running an Illustrator ExtendScript on MacOS and am trying to get the user initials without having to ask for them from the user.  I thought I could try using the long user name from the system as one option...

 

I can use this Shell command to return the initials:

 

dscl . -read /Users/$(whoami) RealName | tail -n 1 | awk '{ for(i=1;i<=NF;i++) printf "%s", tolower(substr($i,1,1)) }'

 

Or this AppleScript:

 

tell application "System Events"
	set fullName to words of (long user name of (system info))
	set initials to ""
	repeat with namePart in fullName
		set initials to initials & character 1 of namePart
	end repeat
	return initials
end tell

 

How do I run either of these from the Illustrator .jsx and get the results returned to it?

 

I tried saving the Applescript code above in a .app on the Desktop and called it with the following code, but can't figure out how to get the results returned back into the original .jsx:

 

var applescript = new File("~/Desktop/Test.app");
var results = applescript.execute();
alert(results);

 

TOPICS
How-to , Scripting

Views

153

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
Adobe
Engaged ,
Jun 24, 2024 Jun 24, 2024

Copy link to clipboard

Copied

From the ExtendScript documentation:

 

18.5.5 execute()

fileObj.execute()

Opens this file using the appropriate application, as if it had been double-clicked in a file browser. You can use this method to run scripts, launch applications, and so on.

Returns true immediately if the application launch was successful.

 

Using JSX’s `execute` to run external scripts is limited and fragile. What you really want is an `app.doScript()` method as in InDesign, but AI doesn’t provide that. You could use `execute` to run an AppleScript app that writes the information to a temporary file at a known location; the JSX script can then wait until the file exists to read the information from it, then delete it.

 

Alternatively, if you can settle for using the current user’s login name, you can read the OS’s environment variables via JSX’s global “dollar” object:

 

 

$.getenv('USER')

 

 

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
Participant ,
Jul 01, 2024 Jul 01, 2024

Copy link to clipboard

Copied

LATEST

Thank you. I'll try the temporary file method. The method suggested below only gives the short name unfortunately.

$.getenv('USER')

 

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