NSAppleScript execution fails in sandboxed app
来源:互联网 发布:网络运维系统 编辑:程序博客网 时间:2024/06/10 09:50
2down votefavorite
I have a sandboxed app targeting Mac OS X 10.7, and want to execute this AppleScript:
tell application "Safari" to add reading list item "http://www.apple.com"
I have tested this script in the AppleScript Editor, and it executes correctly.
In the Cocoa app, I have setup the appropriate temporary entitlements, and tested it with the following script, which executes properly:
tell application "Safari" to activate
But when I insert the first script in my Cocoa app, I get an error. Here is the code I am using
NSString *url = [post.url absoluteString]; NSString *source = [NSString stringWithFormat:@"tell application \"Safari\" to add reading list item \"%@\"", url]; NSDictionary *errorDictionary; NSAppleScript *script = [[NSAppleScript alloc] initWithSource:source]; if ( ![script executeAndReturnError:&errorDictionary] ) { NSLog(@"Error while saving to Safari Reading List: %@", errorDictionary); }
The error is
2012-09-20 10:30:29.370 Cream[2752:303] Error while saving to Safari Reading List: {NSAppleScriptErrorBriefMessage = "A identifier can\U2019t go after this identifier.";NSAppleScriptErrorMessage = "A identifier can\U2019t go after this identifier.";NSAppleScriptErrorNumber = "-2740";NSAppleScriptErrorRange = "NSRange: {29, 11}";}
The error seems to refer to the term 'reading'. It's as though it hasn't loaded the Safari scripting dictionary, and doesn't understand what 'reading list item' means.
If I run the app with sandboxing disabled, it works perfectly with exactly the same script.
Anyone know what could be going on? Do I need to punch another hole in the sandbox somewhere?
2 Answers
Turns out the problem was using the bundle id com.apple.Safari in the entitlements, instead of com.apple.safari.
Sandboxed apps cannot send AppleEvents to other apps, hence they cannot use AppleScript to communicate with other applications.
- NSAppleScript execution fails in sandboxed app
- Drag and drop into sandboxed App
- 在 Sandboxed Mac App 中嵌入第三方可执行文件
- How to Codesign Growl.framework for Sandboxed Mac App
- Xcode: app validation(submission) fails
- app:transformClassesWithDexForDebug Execution问题解决
- Error:Execution failed for task ':app:packageDebug'. > Duplicate files copied in APK META-INF/LICENS
- Error:Execution failed for task ':app:packageDebug'. > Duplicate files copied in APK META-INF/LICENS
- Speculative Execution in Hadoop
- Exceptions in Shipping Execution
- Speculative Execution in Hadoop
- Why Agile Adoption Fails in Some Organizations
- calculating execution time in c++
- angr path in symblic execution
- VMware Tools installation fails when Easy Install is in progress
- Website fails to load when project open in VS 2013
- [Android Studio] Gradle fails to resolve dependencies in Android Studio
- ltib - fails to build Busybox in Ubuntu 12.04
- 谈谈学习方法
- OPPO使用Google三件套教程
- C#当前页面跳转当前页面
- Javascript静态变量与实例变量
- hibernate5--1.入门及核心API
- NSAppleScript execution fails in sandboxed app
- IE矩阵滤镜Matrix旋转与缩放及结合transform的拓展
- 中科院计算所培训中心|大数据专业术语汇总!
- mybatis二级缓存之ehcache
- 机器学习第三章复习(2)
- 【REST】REST、RESTFUL的理解以及SpringMVC实现Restful编程
- 横坐标为数值型;纵坐标为类目型,且在折线图右侧
- ASP.NET Core如何使用Entity Framework
- HTML5的新特性--基础知识(2)