Macos Applesricpt如何将文件移动到/Library/Caches

Macos Applesricpt如何将文件移动到/Library/Caches,macos,applescript,applescript-objc,Macos,Applescript,Applescript Objc,我正在编写一个applesript代码,允许用户自定义登录/更改用户屏幕的背景。目前我正在使用基本的applescript ui,但如果成功的话,我希望实现更高级的applescript objC ui。目前我无法将图像“Chu pic”移动到/library/Caches,请您帮助我解决此问题 set ch_pic to (choose file) --Creates variables for paths --Creates application folder in user lib

我正在编写一个applesript代码,允许用户自定义登录/更改用户屏幕的背景。目前我正在使用基本的applescript ui,但如果成功的话,我希望实现更高级的applescript objC ui。目前我无法将图像“Chu pic”移动到/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"

如果你问我,我会把你的名字写在成品的代码中。

如果你只是选择、移动和重命名一个文件,这很简单。只需确保您所说的是Applescript理解的路径样式

下面是一个代码示例:

-- 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
——将CHU pic设置为所选文件(仅限于可识别的“图像”类型)
将CHU pic设置为(选择“public.image”类型的文件)
告诉应用程序“查找器”
--将cache\u文件夹设置为缓存目标(~/Library/Caches)作为Applescript路径(:Users::Library:Caches)
将cache_folder设置为((用户域中的库文件夹路径为文本)和“Caches”))
--把文件复制过来
将文件chu pic复制到文件夹cache\u文件夹
--抓取新放置文件的完整Applescript路径(为了清晰起见,分两步进行。1:设置路径。2:明确通知Applescript这是一个文件)
将新图片设置为((将文件夹缓存为文本)&“&图片名称)
将位置新图片设置为(文件新图片)
--执行重命名
将pos_new_pic的名称设置为“com.apple.desktop.admin.png”
结束语

如果您只是选择、移动和重命名一个文件,那么这非常简单。只需确保您所说的是Applescript理解的路径样式

下面是一个代码示例:

-- 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
——将CHU pic设置为所选文件(仅限于可识别的“图像”类型)
将CHU pic设置为(选择“public.image”类型的文件)
告诉应用程序“查找器”
--将cache\u文件夹设置为缓存目标(~/Library/Caches)作为Applescript路径(:Users::Library:Caches)
将cache_folder设置为((用户域中的库文件夹路径为文本)和“Caches”))
--把文件复制过来
将文件chu pic复制到文件夹cache\u文件夹
--抓取新放置文件的完整Applescript路径(为了清晰起见,分两步进行。1:设置路径。2:明确通知Applescript这是一个文件)
将新图片设置为((将文件夹缓存为文本)&“&图片名称)
将位置新图片设置为(文件新图片)
--执行重命名
将pos_new_pic的名称设置为“com.apple.desktop.admin.png”
结束语

回到这里以防万一。如果此答案解决了您的问题,请将其标记为已解决。谢谢,回到这里以防万一。如果此答案解决了您的问题,请将其标记为已解决。非常感谢。