2012-08-29 114 views
7

所以我試圖創建一個服務,該服務將位於Finder的上下文菜單中,並允許在當前目錄中創建一個新文檔。創建一個automator服務在當前目錄中創建一個新文檔

我一直在做的是使用的Automator: Automator project 對不起一切都在法國^^

反正這裏是我使用檢索當前工作目錄中的AppleScript:

on run {input, parameters} 
    tell application "Finder" 
     set pwdAlias to insertion location as alias 
     if not (exists folder pwdAlias) then 
      set pwdAlias to (container of pwdAlias) as alias 
     end if 
    end tell 
    set pwd to POSIX path of pwdAlias 
    return pwd 
end run 

然後我將這個值設置爲一個變量,然後使用該變量創建一個新的文本文檔作爲文檔的路徑,最後我使用Finder中的Reveal命令顯示創建的文檔。

一切都工作正常,但劇本似乎總是遲到! 我的意思是,當我打開一個新的Finder窗口,並選擇我的服務,它是系統創建一個窗口上的文件,如下圖所示: Selecting Create a new document The document is created at the wrong location

不過,如果我嘗試第二次,文件被在預期位置進行正確創建: Trying again to create a new document This time the document is created properly!

這是非常系統碰巧每次!

對不起,如果我不是很清楚,這不是很容易解釋!

好,否則,我運行的山獅,這裏是連接的Automator的項目:/ create_new_document

要添加只需要解壓縮服務,並把該文件在〜/庫/服務

希望能得到一些答案,但我擔心這只是一個Automator錯誤!

+1

順便說一句,你的服務的鏈接被打破了! – markhunte

回答

3

這是一個open bug in 10.7 and 10.8

使用此解決方法

on run {input, parameters} 
    activate application "System Events" 
    activate application "Finder" 
    tell application "Finder" 
     set pwdAlias to insertion location as alias 
     set pwdAlias to (container of pwdAlias) as alias 
    end tell 
    return POSIX path of pwdAlias 
end run 
+0

嘿感謝您的快速回復!以及我已經試過這個腳本,但它給了我非常隨機的結果;我正在嘗試在「我的文檔」中創建文檔,並且正在創建我的用戶文件夾中的文檔〜。所以我通過使用輸入的路徑:'set pwd to(第一項輸入的POSIX路徑)'來做這個有點不同的事情。它不像我所希望的那樣通用,但它正在完成這項工作! – guitio2002

6

試試這個enter image description here

  • 根據你想要的東西被點擊

設置選擇的服務: '文件夾' 或文件或文件夾。在'Finder中。應用'

  • 獲取第一Finder窗口路徑行動

您也可以下載獲取第一Finder窗口路徑行動my blog post here 下載是在後的bottom。 該動作獲取最前面的發現者窗口的posix路徑。 由於您正在單擊窗口中的文件夾。該窗口將成爲返回的窗口。

  • 的可變

  • 設定值獲取指定的文本

下一個動作 '新建文本文件' 需要一定的投入。如果它沒有得到,則不會創建文件。您可以將文本字段留爲空白。只要採取行動就行。

  • 新的文本文件

將變量「路徑」或什麼都你將它命名爲到哪裏:下拉菜單。

你可以在Automator的窗口底部單擊雙藍線來切換工作流程變量列表

workflow Variable List

保存您服務。並嘗試一下。 (可能需要一段時間才能顯示在上下文菜單中。)

+0

參見http://superuser.com/questions/106943/os-x-snow-leopard-finder-automator-item-for-creating-a-new-text-file – mems

1

要創建一個新文件,只需點擊一下鼠標,即可使用液滴(查找器工具欄內的按鈕,可從任何查找器訪問窗口)。 在網上搜索了一個多小時後,我終於找到了LINK:

http://www.screenr.com/cNH 和文本版本: http://blog.themeforest.net/general/amp-up-productivity-with-os-x-finder-droplets/

歡迎您。

+0

這'TouchDropplet'的東西很好用!感謝您爲我解決這個問題再次花費了一個小時的時間(再次)。 –