2015-01-02 78 views
-1

我寫了一個AppleScript滴,我想:我想在一個AppleScript液滴一旦設置變量,但它讓我將它設置爲每個文件

  1. 拖動一個或多個圖像到液滴
  2. 3個顯示對話框出現問「寬度」,「身高」,「格式」
  3. 過程中的所有使用上述文本丟棄圖片返回的 3顯示對話框

目前的,3個顯示對話框s出現在每個圖像上(例如,出現3個圖像= 9個對話框)。有沒有辦法我只能回答這些對話一次?這裏是我的腳本:

on run 
    display dialog "This is a droplet" 
end run 

on open draggedItems 

set tid to AppleScript's text item delimiters 

--ask for new width 
set newWidth to text returned of (display dialog "New Width" default answer ¬ 
    "45" buttons {"Continue…", "Cancel"} ¬ 
    default button 1) 

--ask for new height 
set newHeight to text returned of (display dialog "New Height" default answer ¬ 
    "45" buttons {"Continue…", "Cancel"} ¬ 
    default button 1) 

--ask for formatType 
set newFormat to text returned of (display dialog "Image Format" default answer ¬ 
    "jpg" buttons {"Continue…", "Cancel"} ¬ 
    default button 1) 
--repeat 
repeat with i in draggedItems 
    set theFile to (i as alias) 
    set theFilePath to (the POSIX path of theFile) 
    set fullFileName to name of (info for theFile without size) 
    set AppleScript's text item delimiters to "." 
    set fileNameNoExtension to first text item of fullFileName 
    --set fileExtension to second text item of fullFileName 
    set AppleScript's text item delimiters to tid 

    do shell script ("/usr/local/bin/convert " & quoted form of theFilePath & " -resize " & newWidth & "x" & newHeight & "\\! ~/desktop/" & fileNameNoExtension & "." & newFormat) 
end repeat 
end open 

回答

0

on open draggedItems已經是一個重複循環,如果你刪除這個液滴4個文件

on open draggedItems 
    display dialog (draggedItems as text) 
end open 

你會得到4組不同的對話框。

你可以做這樣的事情

property askingForNew : true 

on open draggedItems 
    if askingForNew is true then 
     --display dialogs 
     set askingForNew to false 
    end if 
    display dialog (draggedItems as text) 
end open 

或拖上液滴的文件夾,都要經過它(like this)的文件。

+0

您的'askForNew'方法完美地工作。非常感謝。 – thizzle

相關問題