0

I want to write a simple Automator action to scale an image to an an arbitrary percentage. Using the standard Automator actions, I don’t think that’s possible - I need to set the size in the action itself.

My thought is that by adding a Run JavaScript action, I should be able to ask for the percentage and scale the image that way. I’m using JavaScript because I know it well, and feel more at home with it than working with AppleScript.

In the Script Editor, the library includes Image Events, which appears to have a scale method.

Is it possible to access this library from JavaScript in Automator? How would I do that?

I’m on MacOS Big Sur.

Manngo
  • 14,066
  • 10
  • 88
  • 110
  • The question is what you mean by “using JavaScript”. You can write automation scripts on macOS in a flavour of JS known as _JavaScript for Automation_, but you cannot access scripting extensions in a script that runs outside the automation runtime system (which also hosts AppleScript). – kopischke Sep 10 '21 at 16:28
  • @kopischke I mean _JavaScript for Automation_. I’ve edited the text and added another tag for clarification. – Manngo Sep 10 '21 at 23:11

1 Answers1

0

… and the answer is yes:

var imageEvents = Application('Image Events');
var path = '…';
var img = imageEvents.open(path);
img.scale({byFactor: 50/100});
img.save();

It’s just a matter of knowing about the Application() function and interpreting the information in the Library info in Script Editor.

Manngo
  • 14,066
  • 10
  • 88
  • 110