I am in the process of organizing my .applescript files by separating them into different ones for better organization.
Within my JS AppleScript file named Test.applescript
, I am attempting to execute another JS AppleScript file called
Group Tracks Dependency.applescript
. My goal is to pass a parameter into the dependency script and retrieve a return value from it, which creates an array of arrays of iTunes tracks.
In Test.applescript:
(function() {
var app = Application('iTunes');
app.includeStandardAdditions = true;
app.doShellScript('Group Tracks Dependency.applescript');
return "Done";
})();
// For quick logging
function log(obj) {
this.console.log(obj);
}
In Group Tracks Dependency.applescript:
(function(selection) {
return getGroupsOfTracks(selection);
function getGroupsOfTracks(originalTracksArray) {
if (originalTracksArray == null || originalTracksArray.length == 0)
return null;
var tracks = originalTracksArray.slice();
var groups = [];
while (true) {
var group = [];
group.push(tracks[0]);
tracks = tracks.slice(1);
while (true) {
if (!tracks[0]) break;
if (tracks[0].album() != group[0].album())
break;
if (tracks[0].artist() != group[0].artist())
break;
if (tracks[0].discNumber() != group[0].discNumber())
break;
group.push(tracks[0]);
tracks = tracks.slice(1);
}
groups.push(group);
if (!tracks[0]) break;
}
return groups;
}
})();
Upon running the Test script, I encounter an error at line 5 (app.doShellScript
):
Error on line 5: Error: A privilege violation occurred.
I am seeking a solution to bypass this issue. Additionally, I want to make these scripts easily accessible for others to download and use on their own iTunes libraries in the future (although the current setup may not be user-friendly).
If there is no workaround for this problem, would importing another JS AppleScript file serve as a viable solution?