2016-11-12 11 views
-1

以下腳本將放置在automator中的服務創建中。如何使桌面上的鏈接或與服務在碼頭上的鏈接只需按下在自動生成器中執行的蘋果腳本中的所有按鈕

因此打開Automator並選擇新的服務。對於文件和文件夾鏈接,它們被放置在桌面上,只需將應用程序放置在Dock中(您可以在下面的腳本中修改所有你想要的文件)

在automator select實用程序的左側部分,雙擊Execute的AppleScript的腳本,在你看到的窗口打開,在項的右側部分「服務接收一個選擇」選擇「文件和文件夾」。

現在在下面窗口中的「執行一個AppleScript」內

「在運行{輸入,參數}「

你可以把下面的腳本。

on run {input, parameters} 
    set input to POSIX path of input 

    set fich to POSIX path of input 

    set ft to {} 

    set fold to {} 

    set sn to {} 

    set Nm to {} 



    set {file type:ft} to info for POSIX path of fich 

    if ft is not "APPL" then 

     set input to input 

     set vhdoudmg to input as Unicode text 

     set input to POSIX path of vhdoudmg 

     set sn to "" 

     try 

      set {name:Nm} to info for file vhdoudmg 

     end try 

     if sn is "" then 

      set lelien to "/Users/username/Desktop/ 

" & Nm 

     else 

      set lelien to "/Users/username/Desktop/ 

" & sn 

     end if 

     set vhdoudmg to do shell script "ln -s -v " & quoted form of input & " " & quoted form of lelien 

    else 

     set Reponse to display dialog " Choose to create the symbolic link on the Desktop or Application in the Dock " & return buttons {" The link on the Desktop ", " Application in the Dock "} 

     set Choix to button returned of Reponse 



     if " Application in the Dock " is in Choix then 

      try 

       set theFile to POSIX path of input 

      end try 

      try 

       tell application "Dock" to quit 

      end try 

      do shell script "defaults write com.apple.dock persistent-apps -array-add '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</k ey><string>" & theFile & "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>' " 

      try 

       tell application "Dock" to activate 

      end try 



     else 

      set input to POSIX path of input 



      set vhdoudmg to input as Unicode text 

      set input to POSIX path of vhdoudmg 

      set fich to do shell script "echo " & input 

      try 

       set {name:Nm} to info for file vhdoudmg 

      end try 

      set lelien to "/Users/username/Desktop/" & Nm 

      set vhdoudmg to do shell script "ln -s -v " & quoted form of input & " " & quoted form of lelien 



     end if 

    end if 

    return input 

end run 

現在你可以把這個工作流程/用戶/提供yourname /庫/服務,當你點擊你的鼠標按鈕分辯,你去上下文菜單上的11對服務的選擇,你可以看到的名字這個腳本(你在創建時會給它的名字)。

因此打開Automator並選擇新的服務。對於文件和文件夾鏈接,它們被放置在桌面上,只需將應用程序放置在Dock中(您可以在下面的腳本中修改所有你想要的內容)

+1

,就應該替換'/用戶/用戶名/桌面/'用(路徑桌面)'的'POSIX路徑,使腳本便於攜帶。 – vadian

+0

腳本它在這裏你可以讓你想全部 – deek5

+1

我知道,但如果有人嘗試不熟悉AppleScript的腳本,腳本將無法正常工作。 – vadian

回答

0

晚上好, 。

on run {input, parameters} 
    set input to POSIX path of input 
    set fich to POSIX path of input 
    set ft to {} 
    set Nm to {} 

     set {name:Nm,file type:ft} to info for POSIX path of fich 

      set input to input 
      set vhdoudmg to input as Unicode text 
      set input to POSIX path of vhdoudmg 
        set lelien to "/Users/username/Desktop/" & Nm 


       if ft is not "APPL" then 
      set vhdoudmg to do shell script "ln -s -v " & quoted form of input & " " & quoted form of lelien 
     else 
set Reponse to display dialog " Choose to create the symbolic link on the Desktop or Application in the Dock " & return buttons {" The link on the Desktop ", " Application in the Dock "} 

    set Choix to button returned of Reponse 
    if " Application in the Dock " is in Choix then 
       try 
        set theFile to POSIX path of input 
       end try 
       try 
        tell application "Dock" to quit 
       end try 
       do shell script "defaults write com.apple.dock persistent-apps -array-add '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>" & theFile & "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>'" 
       try 
        tell application "Dock" to activate 
       end try 

      else 

       set vhdoudmg to do shell script "ln -s -v " & quoted form of input & " " & quoted form of lelien 

      end if 
     end if 
    return input 
end run 
相關問題