I am trying to create an automator service using cocoa, which will simply create a text file with the name of files selected, at the same path, for which I wrote below code:
- (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;
}
I added below values in info.plist file:
- AMAccepts: Types: Item 0: com.apple.cocoa.url
- AMCategory:AMCategoryPhotos
I imported the action to the automator, and added it to the default service template.
The options selected in input template are:
- Service receives selected: URLs
- in: Finder
- Input is: only URLs
My problem is the service created is not appearing when I am trying to right click a file in finder.
Can anyone suggest if I missed anything?