2014-06-11 69 views
0

我想製作一個文件夾去服務器上,人們可以添加照片,然後腳本將它們發送到正確的位置,但我遇到搜索部分的麻煩。搜索使用蘋果的文件夾

正如你可以在我的代碼中看到的那樣,它發現文件夾發送到哪裏的部分被註釋掉了,因爲我不知道它的語法是什麼。

任何幫助將不勝感激。

global theWatchedFolder 
set theWatchedFolder to choose folder 
on idle 
tell application "Finder" 
    set theDetectedItems to every item of theWatchedFolder 
    repeat with aDetectedItem in theDetectedItems 
     set jobNumber to display dialog "Please enter the job number for this photo." buttons {"Submit", "Cancel"} 
     display dialog "File detected: " & jobNumber 
     --tell finder 
     -- search for jobNumber in (path to desktop) 
     --set jobFolder to top search result 
     --end tell 
     --set colourFolder to jobfolder & /colour 
     move aDetectedItem to the desktop --move to colourFolder 
    end repeat 
end tell 
if theDetectedItems is not {} then 
    activate 
    display dialog "test move complete" 
end if 
return 1 
end idle 

另外,我很擔心,如果這個腳本是在服務器上,看着服務器上的文件夾,那麼就不會創建一個彈出的人誰增加了一個文件夾在服務器上。希望我錯了,但如果有人可以確認這種方式或其他方式,那就太棒了。謝謝:)

+0

即使鏈接到另一個網站,告訴我如何做到這一點就足夠了,我真的需要得到這一點的代碼工作:( –

回答

1

我可以證實你最大的恐懼。顯示對話框顯示在作爲目標的Finder中。除非使用遠程事件,否則您將始終在運行腳本的同一臺計算機上處​​理Finder。如果腳本在服務器上運行,則該對話框將出現在運行在服務器上的Finder中。

我也有一個方面說明,你不斷保持運行AppleScript使用空閒處理程序來檢查特定文件夾中的任何更新。你知道AppleScript有內存泄漏作爲一個開放的應用程序嗎?它是你不想在服務器上不斷運行的軟件。偶爾會有一個新的AppleScirpt啓動(我喜歡每小時更新一次)並退出當前運行的程序。您仍然可以使用閒置處理程序,但如果閒置處理程序每​​10秒運行一次,我會退出此腳本並在600循環後啓動一個新處理程序。

然後返回到您的搜索。 Finder沒有搜索命令。由於Mac OS X Tiger Apple引入了Spotlight,一種用於查找不同類型數據(文件,捆綁包,郵件等)的元數據庫。然而,聚光燈從來沒有腳本,但只能使用mdls,mdfindmdutil在命令行上訪問AppleScript。要在命令行上執行命令,我們使用AppleScript中的do shell script命令或do script命令來編寫Terminal.app腳本。因爲我們在shell工作返回的路徑是它可以在任何地方通過POSIX文件前綴的路徑使用POSIX路徑:這裏是如何與一個做shell腳本命令

set theFolder to choose folder 
set searchKey to "the*" --use * as wild card 

findMetaDataInFolderByName(theFolder, searchKey) 

on findMetaDataInFolderByName(HFSPath, searchKey) 
    set options to " -onlyin " & quoted form of POSIX path of HFSPath 
    set options to options & " \"kMDItemFSName == " & quoted form of searchKey & "\"" 
    return paragraphs of (do shell script "mdfind " & options) 
end findMetaDataInFolderByName 

注意要使用一個例子

但是,您提到搜索必須在服務器上調用。通常,當您正確安裝服務器時,共享位於應用程序和用戶主文件夾之外。這些文件夾默認僅由聚光燈索引,因此聚光燈需要動態索引。換句話說,與正常的聚光燈搜索相比,它的速度非常慢,而且只需不到一秒的時間。所以我會建議與上面相同的腳本的另一個版本,但使用find。 Find將簡單地遞歸到指定的目錄並打印每一個匹配項。

set theFolder to choose folder 

set searchKey to "the*" --use * as wild card 
findFilesInFolderByName(theFolder, searchKey) 

on findFilesInFolderByName(HFSPath, searchKey) 
    --the HFSPath can't have a trailing "/" 
    set UFSPath to POSIX path of HFSPath 
    if UFSPath ends with "/" and UFSPath is not "/" then set UFSPath to text 1 thru -2 of UFSPath 
    set options to space & quoted form of UFSPath 
    set options to options & " -iname " & quoted form of (searchKey) --iname is case insensitive file name match 
    paragraphs of (do shell script "find " & options & " -print 2>/dev/null ; exit 0") --pipe error to /dev/null to exclude permission denied messages 
end findFilesInFolderByName 

注:一個副作用是,因爲發現將盡一切文件,而元數據搜索的工作原理不同,你可能會發現,現在更多的文件,因爲文件夾包含在搜索也是如此。就像findMetaDataInFolderByName(),findFilesInFolderByName()將返回posix路徑。

+0

不是我想聽到的真的,但至少我現在知道。只是希望我知道之前,我告訴我的老闆,我可以對其進行分類:/ Epicly詳細的答案雖然,你更值得賞金:) –

+1

從我的理解是,你想添加一張照片到一個文件夾,並要求用戶(客戶端),同時將照片添加到服務器。您可以掛載不可見的網絡共享(只需將其掛載到/ Volume目錄之外)。然後讓你的腳本可以放置,這樣用戶就可以放下你的腳本上的照片。然後詢問工作號碼,然後將文件隱藏到網絡卷中。這不是你問的問題,而是它接近你最終想要的。 –