AppleScript在Server 2022服务器创建目录失败:只读文件系统错误
问题分析与解决
你的脚本报错是因为错误处理了网络共享路径格式:targetFolder是file://开头的网络URL字符串,直接用POSIX path of targetFolder会生成/file/bggol-vesko01.boone.local/...这种无效路径——shell会把/file当成本地根目录下的文件夹,而根目录默认只读,自然创建失败。
两种修复方案:
方案1:用Finder直接创建文件夹(推荐,适配AppleScript网络路径处理)
把shell的mkdir命令换成Finder原生的文件夹创建操作,Finder能直接解析file://格式的网络路径:
tell application "System Events" tell application "Google Chrome" activate tell application "System Events" to tell process "Google Chrome" to open location "http://boonegraphics.myprintdesk.net/DSF/PreviewPdf.ashx?1vIGcx4dg0fGKdUPOijyz3th135nK6adXcXoquct9+GghoEmtIsfjU0PAw2gKZT5+ikF0gJTgDShYOIH2pxK7eZOrBnC4UaAs80fvactWGLNSRnxGGWb4HcqOkGF7u4tjwD8bwz1eT0TxWrzQt6m90Y4IbC0D/KSL9TFVyZz9H/XIUmA49CnHQ==" end tell delay 3 --Move file to customer supplied folder of applicable job then delete downloaded file from this computer tell application "Finder" set myFolder to ("Macintosh HD:Users:scriptrunner2021:Downloads:") as alias set targetFolderPath to ("file://bggol-vesko01.boone.local/Jobs_23/90528_FiveCitiesFireAuthority/Customer Supplied/PartNum1") as POSIX file as alias -- 检查文件夹是否存在,不存在则创建 if not (exists targetFolderPath) then make new folder at container of targetFolderPath with properties {name:"PartNum1"} end if set myFile to get every item of (entire contents of folder myFolder) move myFile to targetFolderPath with replacing delete every item of (entire contents of folder myFolder) end tell end tell
方案2:正确转换网络URL到POSIX路径(坚持用shell命令的话)
先把file://字符串转换成POSIX file对象,再提取有效POSIX路径,避免生成/file/开头的错误路径:
tell application "System Events" tell application "Google Chrome" activate tell application "System Events" to tell process "Google Chrome" to open location "http://boonegraphics.myprintdesk.net/DSF/PreviewPdf.ashx?1vIGcx4dg0fGKdUPOijyz3th135nK6adXcXoquct9+GghoEmtIsfjU0PAw2gKZT5+ikF0gJTgDShYOIH2pxK7eZOrBnC4UaAs80fvactWGLNSRnxGGWb4HcqOkGF7u4tjwD8bwz1eT0TxWrzQt6m90Y4IbC0D/KSL9TFVyZz9H/XIUmA49CnHQ==" end tell delay 3 --Move file to customer supplied folder of applicable job then delete downloaded file from this computer tell application "Finder" set myFolder to ("Macintosh HD:Users:scriptrunner2021:Downloads:") set targetFolderURL to ("file://bggol-vesko01.boone.local/Jobs_23/90528_FiveCitiesFireAuthority/Customer Supplied/") & "PartNum1" -- 先转成POSIX file对象,再取正确的POSIX路径 set targetPOSIXPath to POSIX path of (targetFolderURL as POSIX file) do shell script "mkdir -p " & quoted form of targetPOSIXPath set finalFolder to targetFolderURL as POSIX file delay 5.0 set myFile to get every item of (entire contents of folder myFolder) move myFile to finalFolder with replacing delete every item of (entire contents of folder myFolder) end tell end tell
额外注意事项
- 确认运行脚本的用户对
bggol-vesko01.boone.local的共享文件夹有读写权限,虚拟化服务器可能调整了权限策略; - 尽量避免用固定时长的
delay,可改用监听Downloads文件夹文件状态的逻辑,提升脚本稳定性。
内容的提问来源于stack exchange,提问作者BobTucker
相关产品推荐
相关产品推荐

