我正在编写一个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"如果你问我,我会把你的名字写在成品的代码里。
发布于 2016-07-27 09:13:30
如果您只是选择、移动和重命名文件,则非常简单。只需要确保你说的是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 tellhttps://stackoverflow.com/questions/38548249
复制相似问题