Applescript - 将参数保存到文本文件

时间:2015-06-17 14:21:52

标签: applescript

我需要写一个简单的AppleScript,它将以参数打开。该参数将是一个文件路径。我需要它将此文件路径保存到文本文件。我想避免使用shell脚本。

我发现这个令人惊讶的困难,尽管已经在.sh和.bat中完成了

非常感谢!

亚当

////当前无法正常工作的代码如下。代码以“运行中”开头,以“结束运行”结束但由于某种原因,这不会被突出显示为代码

on run argv
    set this_PATH to (POSIX file argv)

    tell application "TextEdit"
        activate
        make new document
        set text of document 1 to this_PATH as text
        save document 1 in "/Users/adamparkinson/Desktop/date.txt"
    end tell
end run

2 个答案:

答案 0 :(得分:0)

我做了这个工作:

#!/usr/bin/osascript

on run argv

    tell application "TextEdit"
        activate
            make new document
            tell document 1
                set its text to (item 1 of argv as text)
                save in posix file (item 1 of argv as text ) 
            end tell
        end tell
end run

我这样称呼它:

./SavePath.sh /Users/Me/Desktop/junk/Newstuff.txt(当然我使用chmod u+x SavePath.sh使其可执行。) 如果这适合您,那么请检查我的答案作为答案。 :)

答案 1 :(得分:0)

使用applescript很容易创建应用程序Drag and Drop没有任何脚本shell下面的版本拖放脚本

 on open draggedItems
    set this_PATH to quoted form of POSIX path of draggedItems
    repeat with currentItem in draggedItems
tell application "TextEdit"
    activate
    set doc to open POSIX file "/Users/adamparkinson/Desktop/date.txt"
    make new word at end of text of doc with data (this_PATH as text) & return
end tell        
    end repeat
end open