Need Help in Converting AppleScript to JXA

I am asking for some help. I have a couple of Applescripts a want to convert to JXA. If some kind soul would "translate" the below to JXA I am going to try to that for the other scripts.

This is the script:

tell application "Finder"
set activeApps to name of application processes whose frontmost is true
set currentApplication to item 1 of activeApps
set frontWindow to the first window of application process currentApplication
set windowSize to size of frontWindow
set windowPosition to position of frontWindow
end tell

Get the bounds of the screen

tell application "Finder"
set screenBounds to bounds of window of desktop
end tell

Move to left

set newWindowPositionX to (item 1 of windowPosition) - 2500
if newWindowPositionX < 0 then set newWindowPositionX to item 1 of screenBounds
set newWindowPositionY to item 2 of windowPosition

Set the new window position

tell application "Finder"
set position of frontWindow to {newWindowPositionX, newWindowPositionY}
end tell

I hope you don't mind that I have revised your topic title to better reflect the question you have asked.

Kindly ask for help

Need Help in Converting AppleScript to JXA

This will greatly help you attract more experienced users to help solve your problem, and will help future readers find your question, and the solution.

Here are some resources to help you learn JXA:

JXA Resources

In the future, please post all of your scripts in KM Forum Code Blocks.

Might I ask what the motivation would be in converting them? Learning? Integration with new code?

I have twenty or so Applescripts I want to convert ultimately to JXA but I do not have the skills to convert them by myself without a good coded example.
If I have an example like the one posted converted I am probably able to it for my other scripts.
Secondly it is a learning process for me.

1 Like

It will take research, but this should get you started

// Gets instance of Finder

var finder = Application("Finder");

// Gets the Active Application

var activeApplication = Application.currentApplication();

// Frontmost Window of Active Application

var frontWindow =[0];

// Get Window Information (Location x/y, Size width/height)

// windowSize.x

// windowSize.y

// windowSize.width

// windowSize.height

var windowSize = frontWindow.bounds();

// Gets instance of Desktop

var desktop = finder.desktop.window();

// Get Window Information (Location x/y, Size width/height)

// windowSize.x

// windowSize.y

// windowSize.width

// windowSize.height

var desktopSize = desktop.bounds();

// Moves the front most window
frontWindow.bounds = {"x":183, "y":45, "width": windowSize.width, "height": windowSize.height}

I had forgot about this Apple guide:

Mac Automation Scripting Guide

It has lots of examples comparing AppleScript to JXA.