Okay, I have included the code for your JSX script and the AppleScript application you need to also have. To make things simple, everything is setup to work from the desktop but you can edit the paths to whatever works best for your situation. Please note, the AppleScript must be saved as an app, so when you go to save make sure you choose "Application" in the file format dropdown menu. You should also run the AppleScript app manually first by double-clicking it to ensure you allow it the necessary permission to run correctly.
Try this out and let me know if you have any questions?
ZipFolder.jsx
(function () {
// set path of text file with folder path
var file = new File(Folder.desktop + "/" + "folder_path.txt");
// set path to bash script
var script = new File(Folder.desktop + "/" + "ZipPath.app");
// choose a folder to zip (could be hardcoded or relative to current doc without dialog)
var folder = Folder.selectDialog("Choose a folder to zip.");
// no need to continue if the user doesn't select a folder
if (!folder) {
return;
}
// write folder path to the text file
try {
file.encoding = "UTF-8";
file.open("w");
file.write(folder.fsName);
// run the bash script
var result = script.execute();
if (!result) {
alert("Oops! Something went wrong with the bash script.");
}
} catch (e) {
alert("Error writing file " + file + "!\n\n" + e);
return false;
} finally {
f.close();
}
})();
ZipFolder.app
-- ZipFolder.app
-- Notes:
-- * must be saved as an AppleScript application
-- * make sure to run the AppleScript first by double-clicking it to enable proper system permissions
-- Path to the text file containing the folder path
set pathToTextFile to "/Users/jbd/Desktop/folder_path.txt"
-- Read the first line from the file as the folder path
set folderPath to paragraph 1 of (read (POSIX file pathToTextFile) as «class utf8»)
-- Break folder path into parent and name
set AppleScript's text item delimiters to "/"
set pathParts to text items of folderPath
set folderName to item -1 of pathParts
set parentPath to "/" & (text items 1 thru -2 of folderPath as string) & "/"
-- Construct zip path
set zipFile to parentPath & folderName & ".zip"
set quotedZipFile to quoted form of zipFile
set quotedFolderName to quoted form of folderName
set quotedParentPath to quoted form of parentPath
-- Remove old zip file if it exists
do shell script "rm -f " & quotedZipFile
-- Zip the folder
do shell script "cd " & quotedParentPath & " && zip -r " & quotedZipFile & " " & quotedFolderName
-- Notify user
display dialog "Compression complete: " & folderName buttons {"OK"} default button 1