Cocoa + Automator : service to generate text files not working
Cocoa + Automator : service to generate text files not working
- Subject: Cocoa + Automator : service to generate text files not working
- From: Devarshi Kulshreshtha <email@hidden>
- Date: Tue, 27 Aug 2013 14:32:06 +0530
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 name 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:
1. Service receives selected: URLs
2. in: Finder
3. 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?
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden