Applescript Droplet文本作为输入

时间:2011-07-04 04:04:03

标签: applescript

如何创建一个将文本选择作为输入的Droplet?当我创建一个以on run inputText开头的脚本时,生成的应用程序图标只会在文件被拖过它时变暗。

4 个答案:

答案 0 :(得分:1)

使用Automator到make a service可以获得类似的结果。服务可以输入选定的文本,(或网址或文件等),而不仅仅是来自Finder,而是来自右键单击上下文菜单或“服务”菜单。你可以在Automator脚本中运行applescript,所以基本上Automator会为你的appleScript创建一个包装器。缺点是它往往比苹果更慢。

答案 1 :(得分:1)

AppleScript中的Dropplet仅支持文件。您可以按照@ stib的建议使用Automator服务或使用Scripts菜单(启动AppleScript Editor并从菜单栏中选择AppleScript Editor> Preferences,在Preferences窗口中选择General,然后选中“在菜单栏中显示脚本菜单”)。然后,您可以将脚本放在/ Library / Scripts /或〜/ Library / Scripts文件夹中,以使脚本显示在菜单中。或者,查看FastScripts以包括为脚本和增强菜单组织分配键盘快捷键的功能。

答案 2 :(得分:-1)

在AppleScript中,您可以创建一个简单的Droplet:

on open theThing
    set fileToRead to open for access theThing --open the file so we can perform operations on it
    set myVar to (read fileToRead) --The myVar variable is set to the contents of the dropped file
    display dialog myVar --Shows the contents of the file in a dialog; do what you want with the text here
    //other code here
    close access fileToRead 
end open

所以,这不是太难,只要确保你打开首先访问该文件。我希望这有帮助!

有用的链接:

http://macscripter.net/viewtopic.php?id=24772:关于Droplets

http://macscripter.net/viewtopic.php?id=24745:关于文件IO

答案 3 :(得分:-1)

据我所知,这只能通过将Applescript包装在Cocoa应用程序中来实现。我不知道Objective-C,但能够拼凑一些东西。当我有机会时,我会尝试清理一下并发布解释。

相关问题