- (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 imported the action to the automator, and added it to the default service template.
1. Service receives selected: URLs
2. in: Finder