Macos 使用在浏览器中打开php文件http://localhost 用苹果笔迹

Macos 使用在浏览器中打开php文件http://localhost 用苹果笔迹,macos,applescript,mamp,textwrangler,localhost,Macos,Applescript,Mamp,Textwrangler,Localhost,我正在尝试为textwrangler编写一个Applescript,它将在Chrome中打开活动文档。这就是脚本目前的样子: tell application "TextWrangler" to set theFile to file of document 1 tell application "Finder" to open theFile using (path to application "Google Chrome") 假设我正在处理一个绝对路径为“Applications/MAM

我正在尝试为textwrangler编写一个Applescript,它将在Chrome中打开活动文档。这就是脚本目前的样子:

tell application "TextWrangler" to set theFile to file of document 1
tell application "Finder" to open theFile using (path to application "Google Chrome")
假设我正在处理一个绝对路径为“Applications/MAMP/www/index.php”的文件。脚本将在浏览器中以“file://localhost/Applications/MAMP/www/index.php”的形式打开该文件,显示php代码

我需要一个脚本,将“file://localhost/Applications/MAMP/”替换为显示实际站点的“http://localhost/”


我在网上找到了很多东西,但我对Applescript的经验太少,无法做到这一点。

如果您想打开该url,您可以使用以下方法:

tell application "Safari"
    activate
    do JavaScript "window.open('http:// localhost/')" in document 1
end tell

希望这能有所帮助。

这个怎么样,跟随Chase的思路,用javascript替换字符串

property delim : "MAMP" -- where to break the path and prepend localhost to

tell application "TextWrangler" to set theFile to file of document 1

tell application "Finder" to set p to the POSIX path of theFile -- convert it into a Unix path first

tell application "Google Chrome" to execute front window's active tab javascript ("pth='" & p & "';window.open('http://localhost'+ pth.split('" & delim & "').pop());")

使用多语言连接和字符串分隔使代码难以阅读,但它应该可以工作。

这里有几个不同的选项

第一个假设您要打开的文件位于根localhost目录。脚本将指示Safari打开URL并将文件名附加到路径

第一次运行此程序时,可能需要授权Mac Accessibility,以便Finder完成必要的操作

试试看
告诉应用程序“Finder”将文件路径设置为的项目1的名称(获取选择)
将剪贴板设置为filePath
将localhost设置为“http://localhost/"
告诉应用程序“Safari”
激活
告诉应用程序“系统事件”
告诉流程“Safari”
单击菜单栏1的菜单“文件”的菜单项“新建选项卡”
结束语
结束语
将URL设置为本地主机和文件路径
将文档1的URL设置为URL
结束语
结束语
结束尝试

另一个选项是复制所选文件的POSIX路径,并在Safari中打开本地路径

试试看
将filePath设置为{}
告诉应用程序“查找器”
在objItem中重复(获取选择)
将文件路径的结尾设置为的POSIX路径(objItem作为文本)
结束重复
结束语
将{strDelimeter,text item delimiters}设置为{text item delimiters,return}
将剪贴板设置为文本文件路径
告诉应用程序“Safari”打开位置文件路径
结束尝试

为了提交此问题,我在localhost之前有空格。谢谢,但我要找的是基本上修剪原始路径(字符串?),然后将“”位添加到其开头。您可以只添加一个包含字符串的变量,然后使用&&将其放入报告中吗?谢谢!这就是我要找的。