我经常保存网页供将来使用,并希望尝试简化这一过程。
说我打开了狩猎和探测仪。Finder包含我的当前项目。我浏览网页研究并找到一些感兴趣的东西,然后我把网页地址从safari拖到finder --这将创建一个.webloc链接。
这是不理想的,有几个原因;
理想情况下,我想要做的是将网站捕获为PDF格式。我知道我可以选择适当的菜单选项导出为PDF,或打印/保存为PDF等。但是它中断了我的工作流程,因为它涉及更多的步骤,而且还必须指定要导出到每个时间的文件夹。
我认为Automator / Apple脚本可能会有所帮助,下面的伪代码是这样的:
If finder has item dropped on it
If the item is a URL or .Webloc
Use Safari’s built in functionality to generate a PDF from the URL in the folder the item was dropped on
end if
end if然而,我确实发现我与AppleScript斗争,所以有人能告诉我,如果这是可能的,甚至在我潜入之前?
提前谢谢。
发布于 2016-12-28 11:27:36
最好的方式来做你想做的事情,所以混合一个自动化服务和一个AppleScript。
Automator服务将只包含一个操作“receive”,并将其设置为接收来自Safari的选择文本。AppleScript的操作如下:
on run {input, parameters}
set myPath to "/Users/your_User/Desktop/Test_URL" -- set your default saving path
tell application "Safari"
activate
set myURL to URL of front document
set myURL to my CleanName(myURL)
tell application "System Events" to tell application process "Safari"
click menu item 15 of menu 3 of menu bar 1 -- export as PDF (Safari 10.0.2 / El Capitain)
delay 0.5
keystroke myURL & ".PDF"
delay 0.2
keystroke "g" using {command down, shift down} -- go to dialog
keystroke myPath -- path to saving folder
delay 0.2
keystroke return -- close go to dialog
delay 0.2
keystroke return -- close the save as dialog
end tell
end tell
return input
end run
on CleanName(S) --replace special characters not allowed for file name with _
set AppleScript's text item delimiters to {":", "/", ","}
set SL to text items of S
set AppleScript's text item delimiters to {"_"}
return SL as text
end CleanName 这个脚本运行模拟使用Safari菜单导出作为PDF。如果使用不同版本的Safari,菜单项可能与我的不同。请调整一下。
我假设PDF文件应该基于URL值(最后是+ PDF !)。为此,我还添加了一个子例程来清理URL,将其转换为OK文件名。我将/:这样的所有特殊字符替换为char _。
变量myPath包含到默认保存位置的路径:必须用用户名更改“your_user”,并确保桌面上存在文件夹TEST_URL。该脚本包含许多注释,以帮助您根据特定需求进行调整。
https://stackoverflow.com/questions/41350756
复制相似问题