首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Applesricpt如何将文件移动到/Library/Caches

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

Stack Overflow用户
提问于 2016-07-24 10:41:01
回答 1查看 99关注 0票数 1

我正在编写一个applesript代码,允许用户自定义登录/更改用户屏幕的背景。我目前正在使用基本的applescript ui,但如果这是成功的,我希望实现更高级的applescript-objC UI。目前,我在将图像"ch_pic“移动到/library/Caches时遇到了问题,您能帮我解决这个问题吗?

代码语言:javascript
复制
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"

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-07-27 09:13:30

如果您只是选择、移动和重命名文件,则非常简单。只需要确保你说的是Applescript理解的PATH风格。

以下是代码的示例:

代码语言:javascript
复制
-- 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
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38548249

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档