【问题标题】:How to get the name and path from applescript如何从applescript获取名称和路径
【发布时间】:2015-06-05 16:23:41
【问题描述】:

我有一个文件,比如“123.xyz”,在 TextWrangler 中打开。 如何使用 Applescript 获取当前打开文件的“其绝对路径 + 全名”。 这样我就可以在另一个程序或脚本中使用它。

我修改了一些我在网上找到的代码,但它对我不起作用。

tell application "TextWrangler"
    tell document 1
        -- Get (absolute path + filename) of the current file
        set FileName to «class ppth» as text
    end tell
end tell 

非常感谢任何帮助。

【问题讨论】:

    标签: applescript filenames filepath


    【解决方案1】:
    tell application "TextWrangler"
    
        --This will return the file path of document 1 in the following format: file "Macintosh HD:Users:UserName:Desktop:document1.txt"
        set filePath1 to file of document 1
    
    
        --This will convert the file path of document 1 to the following format: "Users/UserName/Desktop/document1.txt"
        set filePath2 to POSIX path of filePath1
    end tell
    

    【讨论】:

    • 好节目!您可以通过展示如何将上面生成的文件规范传递给 textutil 的 shell 来对此进行扩展:)
    【解决方案2】:

    这个应该工作:

    tell document 1 to set myVeryOwnPath to path as text
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-14
      • 2012-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多