Reputation: 33
I've been trying to execute applescript code through XPCOM, but no matter what I do it just doesn't seem to work, the observer tells me that the process finishes without a problem, but nothing happens.
var processArgs = ['-e','\'tell application "iTunes"\'','-e','\'activate\'','-e','\'end tell\''];
var file = Cc["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsIFile);
file.initWithPath( '/usr/bin/osascript');
var process = Cc["@mozilla.org/process/util;1"].createInstance(Components.interfaces.nsIProcess);
process.init( file );
var observer = {
observe: function( subject, topic ) {
SiteFusion.consoleMessage('DONE ' + topic);
}
}
process.runAsync( processArgs, processArgs.length, observer );
The output in the console is 'DONE process-finished' so it should have worked, does anyone know why this script refuses to open iTunes?
Upvotes: 2
Views: 55
Reputation: 7480
Reason is that you use escaped single quotes in arguments, so your actual resulting AppleScript looks like:
'tell application "iTunes"'
'activate'
'end tell'
Which is clearly not valid. Instead, your arguments should look like this:
const processArgs = ['-e', 'tell application "iTunes"', '-e', 'activate', '-e', 'end tell'];
or, alternatively,
const processArgs = ['-e', `
tell application "iTunes"
activate
end tell`];
or, alternatively,
const processArgs = ['-e', 'tell application "iTunes" to activate'];
Upvotes: 0