Macos Mac OS脚本应该将UNC路径粘贴为SMB,但它会不断将冒号转换为分号,并将大写字母转换为小写

Macos Mac OS脚本应该将UNC路径粘贴为SMB,但它会不断将冒号转换为分号,并将大写字母转换为小写,macos,Macos,我有一个脚本,它应该将Windows UNC路径转换为Mac SMB,但继续将冒号转换为分号,将大写转换为小写。这是代码。谢谢你的帮助 set myClip to the clipboard set mytext to searchReplace(myClip, "<", "") set mytext to searchReplace(mytext, ">.", "") set mytext to searchReplace(mytext, ">", "") set findI

我有一个脚本,它应该将Windows UNC路径转换为Mac SMB,但继续将冒号转换为分号,将大写转换为小写。这是代码。谢谢你的帮助

set myClip to the clipboard
set mytext to searchReplace(myClip, "<", "")
set mytext to searchReplace(mytext, ">.", "")
set mytext to searchReplace(mytext, ">", "")
set findIt to "\\"
set replaceIt to "/"
set mylocation to searchReplace(mytext, findIt, replaceIt)
set mylocation to "smb:" & mylocation

set the clipboard to mylocation

do shell script "pbpaste |textutil -convert txt -stdin -stdout -encoding 30 |pbcopy"
tell application "System Events" to keystroke (the clipboard)

on searchReplace(theText, SearchString, ReplaceString)
    set OldDelims to AppleScript's text item delimiters
    set AppleScript's text item delimiters to SearchString
    set newText to text items of theText
    set AppleScript's text item delimiters to ReplaceString
    set newText to newText as text
    set AppleScript's text item delimiters to OldDelims
    return newText
end searchReplace
将myClip设置为剪贴板
将mytext设置为searchReplace(myClip,“.”,“”)
将mytext设置为searchReplace(mytext,“>”,“”)
将findIt设置为“\\”
将replaceIt设置为“/”
将mylocation设置为searchReplace(mytext、findIt、replaceIt)
将mylocation设置为“smb:”&mylocation
将剪贴板设置为mylocation
执行shell脚本“pbpaste | textutil-convert txt-stdin-stdout-encoding 30 | pbcopy”
告诉应用程序“系统事件”击键(剪贴板)
在searchReplace上(文本、SearchString、ReplaceString)
将OldDelims设置为AppleScript的文本项分隔符
将AppleScript的文本项分隔符设置为SearchString
将新文本设置为文本的文本项
将AppleScript的文本项分隔符设置为ReplaceString
将newText设置为newText作为文本
将AppleScript的文本项分隔符设置为OldDelims
返回新文本
末端搜索替换
此行:

tell application "System Events" to keystroke (the clipboard)
模拟按键。字符串中的字符将转换为相应的键并“按下”,而不使用Shift等修饰符(默认情况下)。您可以在命令上使用短语指定一个
,以指定要使用的修改器,但这些修改器将用于所有模拟按键。您不能使它模拟某些按键(大写字母和冒号)的移位,而不是基于字符串中的字符的其他按键


这似乎是一个很好的候选脚本,而不是一个独立的脚本。服务将自动接收活动应用程序中的选定文本,其输出将自动替换选定文本,而无需使用剪贴板或模拟按键。使用Automator.app创建服务,启用“输出替换所选文本”,添加Run AppleScript操作,并将脚本的内容放入处理程序。

谢谢!这对虚拟机有效吗?我有2个(Windows和Mac)操作系统在Mac上运行。你是说一个服务能跨虚拟机工作吗?不,可能不会。虚拟机托管软件必须特别同步剪贴板,以允许复制和粘贴工作。他们也必须对服务做一些类似的事情,但我怀疑他们会这样做(如果他们想的话,还不完全清楚他们会如何实现)。我认为这就是剪贴板(代码中)使跨系统复制和粘贴变得容易的原因。