Mac 为 DMG 文件创建别名,其中没有固定用户

发布于 2024-09-14 03:26:45 字数 811 浏览 2 评论 0原文

我想将别名放入固定文件夹,即 iWorks 模板文件夹到 DMG 中。

该目录是

/Users/USERNAME/Library/Application Support/iWork/Pages/Templates/My Templates

我的问题是,我想将其放入 DMG 中,以便人们可以轻松安装模板。但是,虽然它在应用程序文件夹中运行良好,但模板文件夹中始终包含我的用户名。因此,如果其他人打开它,别名会指向带有我的用户名的目录,这当然在不同的 Mac 上不存在。

有谁知道如何解决它?

谢谢。


将您的所有评论与以下内容结合起来,我得到了一个按照我想要的方式工作的液滴。

on open thefiles    
    set outputFolder to (path to application support folder from user domain as text) & "iWork:Pages:Templates:My Templates:"
    do shell script "/bin/mkdir -p " & quoted form of POSIX path of outputFolder
    tell application "Finder"
        duplicate thefiles to outputFolder
    end tell    
end open

问题是,虽然它可以在我的 Mac 上运行,但我无法在 DMG 文件中使用它。我无法在上面拖动任何东西。有什么想法吗?

到目前为止谢谢。

I want to put an alias to a fixed folder, namely the iWorks template folder into a DMG.

The directory is

/Users/USERNAME/Library/Application Support/iWork/Pages/Templates/My Templates

My Problem is, that I want to put it into a DMG so people can easily install the template. But while it works fine with the Application folder, the template folder always has my username in it. So if someone else opens it, the alias points to the dir with my username, which of course does not exist on a different mac.

Does anyone have any idea how to fix it?

Thanks.


Combining all of your comments to the following I get a droplet working the way I want.

on open thefiles    
    set outputFolder to (path to application support folder from user domain as text) & "iWork:Pages:Templates:My Templates:"
    do shell script "/bin/mkdir -p " & quoted form of POSIX path of outputFolder
    tell application "Finder"
        duplicate thefiles to outputFolder
    end tell    
end open

The Problem is, while it works on my mac, I can not use it being inside the DMG file. I can not Drag anything on it. Any ideas?

Thanks so far.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

终难愈 2024-09-21 03:26:45

~ 文件夹代表用户的主目录。因此,您的文件夹将为 ~/Library/Application Support/iWork/Pages/Templates/My Templates
回应您的评论:我不确定这是否可行。您可以从终端尝试ln。它是一个用于建立链接的实用程序。但我认为它只是在您使用它时将 ~ 转换为您的主目录的实际路径。我认为你必须创建一个符号链接而不是硬链接,某些文件系统可能不支持(但所有 Mac 都应该支持)。另一种可能性是制作一个简单的 Applescript Droplet,它使用 shell 脚本将您拖到其上的文件移动到您想要的路径。将以下代码粘贴到脚本编辑器中,并将其另存为应用程序或应用程序包(无论是哪个):

on open thefile
 do shell script "mv " & POSIX path of thefile & " ~/Library/Application\ Support/iWork/Pages/Templates/My\ Templates/"
end open

当您将文件拖到您创建的应用程序时,它会将其移动到您的目录。您可以通过右键单击应用程序并选择“获取信息”来更改图标,然后将新图标粘贴到旧图标之上,使其看起来更像一个文件夹。

The ~ folder represents the users home directory. So your folder would be ~/Library/Application Support/iWork/Pages/Templates/My Templates.
In response to your comment: I am not sure if this is possible. You could try ln from Terminal. It is a utility for making links. But I think it just converts ~ to the actual path of your home directory when you use it. And I think you would have to make a symbolic link as apposed to a hard link, which some file systems might not support (All macs should though). Another possibility would be to make a simple Applescript droplet that uses a shell script to move the file you drag onto it to the path you want. Paste the following code into script editor and save it as an Application or Application Bundle (doesn't matter which):

on open thefile
 do shell script "mv " & POSIX path of thefile & " ~/Library/Application\ Support/iWork/Pages/Templates/My\ Templates/"
end open

When you drag a file to the application you made it will move it to your directory. You could change the icon by right clicking on the app and selecting "Get Info", then pasting the new icon on top of the old one, to make it look more like a folder.

且行且努力 2024-09-21 03:26:45

您可以使用这个苹果脚本。将其另存为应用程序并将其包含在您的安装磁盘上。用户所要做的就是运行 applescript 应用程序来安装别名...或者您可以在将应用程序放置在用户的驱动器上后从您自己的代码自动运行它。只需修复 inputFile 变量以指向您的文件即可。在此示例中,我只是从 Address Book.app 应用程序内部抓取了一张图像。

set inputFile to (path to applications folder as text) & "Address Book.app:Contents:Resources:AB16.png"

-- first create the outputFolder if necessary
set outputFolder to (path to application support folder from user domain as text) & "iWork:Pages:Templates:My Templates:"
do shell script "/bin/mkdir -p " & quoted form of POSIX path of outputFolder

-- create the alias in the outputFolder
tell application "Finder"
    make new alias file at folder outputFolder to file inputFile
end tell

You can use this applescript. Save it as an application and include it on your install disk. All a user would have to do is run the applescript application to install the alias... or you can run it automatically from your own code after you place your application on the user's drive. Just fix the inputFile variable to point to your file. In this example, I just grabbed an image from inside the Address Book.app application.

set inputFile to (path to applications folder as text) & "Address Book.app:Contents:Resources:AB16.png"

-- first create the outputFolder if necessary
set outputFolder to (path to application support folder from user domain as text) & "iWork:Pages:Templates:My Templates:"
do shell script "/bin/mkdir -p " & quoted form of POSIX path of outputFolder

-- create the alias in the outputFolder
tell application "Finder"
    make new alias file at folder outputFolder to file inputFile
end tell
甜心 2024-09-21 03:26:45

您需要的是相对别名。

旧包可以创建它们:这个 osxutils

另一种解决方案是创建符号链接。

What you need is relative aliases.

An old package is able to create them: this osxutils.

Another solution is to create a symbolic link.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文