我想創建一個使用可可的automator服務,它將簡單地創建一個文本文件與選定文件的名稱,在相同的路徑,我寫下面的代碼:Cocoa + Automator:服務來生成不工作的文本文件
- (id)runWithInput:(id)input fromAction:(AMAction *)anAction error:(NSDictionary **)errorInfo
{
// Add your code here, returning the data to be passed to the next action.
NSArray *fileURLs = (NSArray *)input;
size_t count = [fileURLs count];
dispatch_apply(count, dispatch_get_global_queue(0, 0), ^(size_t i) {
NSURL *fileURL = [fileURLs objectAtIndex:i];
NSData *data = [@"some crude text ;)" dataUsingEncoding:NSUTF8StringEncoding];
//changing extension of file
NSString *filePathWithoutExtension = [[fileURL path] stringByDeletingPathExtension];
NSString *filePathWithNewExtension = [[NSString alloc] initWithFormat:@"%@.%@",filePathWithoutExtension,@"txt"];
[data writeToFile:filePathWithNewExtension atomically:NO];
});
// no need to return anything
return nil;
}
我加了下面Info.plist文件中值:
- AMAccepts:類型:項目0:com.apple.cocoa.url
- AMCategory:AMCategoryPhotos
我將動作導入到automator中,並將其添加到默認服務模板中。
輸入模板選擇的選項有:
- 服務接收選擇:網址
- 在:搜索
- 輸入是:只有網址
我的問題是創建的服務當我嘗試在查找程序中右鍵單擊文件時沒有出現。
任何人都可以建議,如果我錯過了什麼?
因此,服務不會出現在上下文菜單在Finder中,當你在一個文件上右鍵單擊。您的服務是否出現在Finder應用程序菜單的服務菜單中? – Kaydell