Hi there,
My macOS application is able to control Powerpoint through AppleScript. The first step of controlling is to see if Microsoft Office installed or not. Here is the worked AppleScript:
set appID to "com.microsoft.Powerpoint"
-- check if the application exists
set doesExist to false
try
tell application "Finder" to get application file id appID
set doesExist to true
end try
return doesExist
If the Office is installed, the script returns "true" and "false" vice versa. The script is working under Script Editor and Xcode 8.3.3.
However I upgraded my Xcode to 10.3, the script always return "false". This stops me to do notarization. How my object-C call AppleScript API is as below:
// AppleScript macro
+ (NSString *)pptIsInstalledOrNot
{
return @"\n\
set appID to \"com.microsoft.Powerpoint\" \n\
-- check if the application exists \n\
set doesExist to false \n\
try \n\
tell application \"Finder\" to get application file id appID \n\
set doesExist to true \n\
end try \n\
\n\
return doesExist \n\
";
}
// AppleScript execution
+ (NSAppleEventDescriptor *)runProcess:(NSString *)script
errorDescription:(NSString **)errorDescription
{
NSDictionary *errorInfo = [[NSDictionary alloc] init];
NSAppleScript *appleScript = [[NSAppleScript alloc] initWithSource:script];
NSAppleEventDescriptor *eventResult = [appleScript executeAndReturnError:&errorInfo];
// Check errorInfo
if (!eventResult) {
// Set error message
if ([errorInfo valueForKey:NSAppleScriptErrorMessage]) {
id message = [errorInfo valueForKey:NSAppleScriptErrorMessage];
if (errorDescription) {
*errorDescription = (NSString *)message;
}
}
}
else {
// Set output to the AppleScript's output
}
return eventResult;
}
// main process
Boolean isInstalled = false;
{
NSString *script = [self pptIsInstalledOrNot];
NSString *errorMessage = nil;
NSAppleEventDescriptor *descriptor = [self runProcess:script errorDescription:&errorMessage];
isInstalled = [descriptor booleanValue];
}
I ever tried other ways, still failed. How do I modify my program on XCode 10.3? Appreciate for any ideas and
thanks your time.