Applescript 如何将文件移动到 /Library/Caches
Applesricpt how to move files to /Library/Caches
我正在编写允许用户自定义 login/change 用户屏幕背景的 applesript 代码。我现在正在使用基本的 applescript ui,但如果成功的话,我希望能实现更高级的 applescript-objC UI。目前我在将图像 "ch_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 可以理解的 PATH 样式。
代码示例如下:
-- 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
我正在编写允许用户自定义 login/change 用户屏幕背景的 applesript 代码。我现在正在使用基本的 applescript ui,但如果成功的话,我希望能实现更高级的 applescript-objC UI。目前我在将图像 "ch_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 可以理解的 PATH 样式。
代码示例如下:
-- 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