2016-11-12 67 views
-1

同一個地方有了,我們要創建另一個腳本,將臺式機的所有元素,創建的腳本的商店位置腳本編譯和使用,以恢復原先保護的所有元素。如何保存你的桌面元素(圖標,文件,文件夾)一直在使用AppleScript

/adesktopsave/deskico.txt它是臨時文件,該文件會使用到編譯的。 /adesktopsave/savedicoposition.scpt這是保存的腳本,被編譯爲與蘋果公司一起使用

這裏使用的所有名稱都存在,只是爲了舉例。這些名稱沒有特定的屬性。

只需要計劃在使用此腳本之前創建文件夾。那就是: /adesktopsave

別的東西,之後行(\ n)的結束 「試 」 也 「結束嘗試 」 和& 「} 」)

是尊重很重要以便文本可用。

tell application "Finder" to set theList to {name, desktop position} of items of desktop 
try 
do shell script "rm -f /adesktopsave/deskico.txt" 

do shell script "echo tell application " & quoted form of (quote & "Finder" & quote) & return & " >>/adesktopsave/deskico.txt" 

end try 

set n to (count (first item of theList)) 


repeat with i from 1 to n  

set inp to do shell script "echo " & quoted form of (item i of first item of theList)  

set xy to (item i of second item of theList)  

set AppleScript's text item delimiters to "," 

set xyz to do shell script "echo " & xy  
set wxyz to ("{" & xyz & "} 
")   

set ligne to "try 
" & "set desktop position of item " & quoted form of (quote & inp & quote) & " of desktop to " & quoted form of (wxyz) & "end try 
"  
set ligne to do shell script "echo " & ligne & " >>/adesktopsave/deskico.txt"  

end repeat 

do shell script "echo " & "end tell" & return & " >>/adesktopsave/deskico.txt" 

    display dialog "Do you want to save your icons in their current location?" buttons {"Cancel", "Save"} default button 2 with title "Save the positions of icons" 

    if (button returned of result) is "Cancel" then  
set n to do shell script "echo " & n 
else  
do shell script "osacompile -o " & "/adesktopsave/savedicoposition.scpt" & " /adesktopsave/deskico.txt" 
end if 

return n 
+1

再次,目前還不清楚,你提供_solution_,而不是要求一個_question_(我認爲),並_what問題的解決方案solves_。這個標題既沒有給我提供線索,也沒有在帖子正文中的描述,也沒有多少人會花時間挖掘格式不好的,未註釋的代碼。 – mklement0

+0

我知道這對大家來說不一定是可以理解的。當我問及如何保存桌面元素時,這個問題不妨礙我提出我的答案,顯然其他人很好奇似乎可以改進已經編寫或提出自己解決方案的內容。這是爲那些誰不明白 – deek5

回答

-1

我們可以減輕腳本最簡單的表達。有可能發生錯誤的風險。

set ligne to "" 
do shell script "mkdir -p /adesktopsave" 
tell application "Finder" to set {names, positions} to {name, desktop position} of items of the desktop 
set ligne to "tell application \"Finder\" 
" 
set n to (count names) 
set AppleScript's text item delimiters to "," 
repeat with i from 1 to n 
set ligne to ligne & ("try 
" & "set desktop position of item " & (quote & item i of names & quote) & " to {" & item i of positions & "} 
end try 
") 
end repeat 
set ligne to ligne & ("end tell" & return) 
display dialog "Do you want to save your icons in their current location?" buttons {"Cancel", "Save"} default button 2 with title "Save the positions of icons" 
    if (button returned of result) is "Cancel" then 
    set n to do shell script "echo " & n 
else 
    do shell script "osacompile -o " & "/adesktopsave/savedicoposition.scpt -e " & quoted form of ligne 
end if 
set AppleScript's text item delimiters to "" 
tell application "Finder" to open POSIX file "/adesktopsave/savedicoposition.scpt" 
return n 
+0

根據操作系統,您可能需要大概添加權限,例如, 做shell腳本「的mkdir -p/adesktopsave」用戶名「提供yourname」密碼「yourPW」具有管理員權限, 也爲 做shell腳本「osacompile -o」&「/adesktopsave/savedicosition.scpt -e」&帶形式的行用戶名「yourname」密碼「yourPW」與管理員權限 – deek5

相關問題