2016-07-24 640 views
1

Ich arbeite an einem Applescript-Code, mit dem Benutzer den Hintergrund des Login/ändern Benutzerbildschirm anpassen können. Ich benutze im Moment Basic Applescript ui, hoffe aber, ein fortgeschrittenes applescript-objC UI zu implementieren, wenn dies ein Erfolg ist. Im Moment habe ich Probleme, das Bild "ch_pic" nach/library/Caches zu verschieben. Bitte helfen Sie mir bei diesem Problem.Applesricpt Wie verschiebt man Dateien nach/Library/Caches

set ch_pic to (choose file) 

--Creates variables for paths 


--Creates application folder in user library for storing assets and code 

tell application "Finder" 
move file ch_pic to Library/Caches 
end tell 

--Moves user selected file to application folder 

set the name of file ch_pic to "com.apple.desktop.admin.png" 

Wenn Sie fragen, werde ich Ihren Namen in den Code des fertigen Produkts eingeben.

Antwort

0

Ziemlich einfach, wenn Sie nur eine Datei auswählen, verschieben und umbenennen. Sie müssen nur sicherstellen, dass Sie den PATH-Stil sprechen, den Applescript versteht. Hier

ist ein Beispiel für den Code:

-- Set ch_pic to chosen file (restricting to only recognized "image" types) 
set ch_pic to (choose file of type "public.image")) 
tell application "Finder" 
-- Set cache_folder to Caches destination (~/Library/Caches) as Applescript path (<hard drive name>:Users:<user name>:Library:Caches) 
    set cache_folder to (((path to library folder from user domain as text) & "Caches")) 
    -- Copy the file over 
    copy file ch_pic to folder cache_folder 
    -- Grab the full Applescript path of the newly placed file (two steps for clarity. 1: set the path. 2: explicitly inform Applescript that this is a file) 
    set new_pic to ((cache_folder as text) & ":" & name of ch_pic) 
    set pos_new_pic to (file new_pic) 
    -- Perform the rename 
    set the name of pos_new_pic to "com.apple.desktop.admin.png" 
end tell 
+0

dazu Kommen wir zurück für alle Fälle. Wenn diese Antwort Ihr Problem gelöst hat, markieren Sie es bitte als gelöst. Vielen Dank. – EricDAltman