gpt4 book ai didi

objective-c - cocoa +自动化: service to generate text files not working

转载 作者:行者123 更新时间:2023-12-03 17:53:23 24 4
gpt4 key购买 nike

我正在尝试使用 cocoa 创建一个自动化服务,它将简单地创建一个文本文件,其名称与所选文件的名称相同,路径相同,我为此编写了以下代码:

- (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:AMCategory照片

我将操作导入到自动化程序中,并将其添加到默认服务模板中。

输入模板中选择的选项是:

  1. 服务接收选定的:URL
  2. 在:Finder
  3. 输入为:仅网址

我的问题是当我尝试右键单击查找器中的文件时,创建的服务没有出现。

如果我错过了什么,有人可以建议吗?

最佳答案

有时我会遇到服务未显示的问题,因为我有很多服务。尝试进入以下窗口并通过取消选中某些其他服务的复选框来禁用它们:

系统偏好设置 > 键盘 > 服务

如果您有任何想要删除(或存档)的服务,您可以执行以下操作:

  1. 右键单击服务名称
  2. 选择“在 Finder 中显示”
  3. 这将带您前往 ~/Library/Services/

您可以删除服务或将它们移动到安全的地方。

---编辑---

我一直在关注这个问题。也许,有效的方法是在 Automator 中将服务工作流程的输入指定为“文件和文件夹 > 图像文件”,而不是“文本 > URL”。

您必须在操作中调整 Objective-C 代码以使用路径名而不是 URL,但这是一个想法。

如果我的评论不起作用,您可以给我发电子邮件:kaydell@yahoo.com 我有兴趣了解有关 Automator 的更多信息。

关于objective-c - cocoa +自动化: service to generate text files not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18461385/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com