Terminal MacOS终端等待打开的程序
我使用一个名为PDF Lightweight的应用程序来压缩我的PDF文件(因为我有很好的体验)和Thunderbird来发送电子邮件 我想在将PDF附加到电子邮件之前编写一个压缩PDF的AppleScript:Terminal MacOS终端等待打开的程序,terminal,applescript,Terminal,Applescript,我使用一个名为PDF Lightweight的应用程序来压缩我的PDF文件(因为我有很好的体验)和Thunderbird来发送电子邮件 我想在将PDF附加到电子邮件之前编写一个压缩PDF的AppleScript: set attachment1 to "/Users/username/Desktop/Test.pdf" do shell script "open -a " & quoted form of ("/Applications
set attachment1 to "/Users/username/Desktop/Test.pdf"
do shell script "open -a " & quoted form of ("/Applications/Lightweight PDF.app") & " " & quoted form of attachment1
set email_attachment to "attachment=" & "'file://" & attachment1 & "'"
set thunderbird_bin to "/Applications/Thunderbird.app/Contents/MacOS/thunderbird-bin -compose "
set arguments to email_attachment
do shell script thunderbird_bin & quoted form of arguments & ">/dev/null 2>&1 &"
问题是原始PDF将在压缩完成之前附加。我试着用类似的东西工作,但也不起作用。我想是因为我在启动PDF轻量级时使用了一个“open”命令,从技术上讲,这个命令是完整的,即使应用程序还在压缩
你知道如何让脚本等待PDF压缩吗
谢谢大家! 我现在通过查看文件大小来解决问题。一旦工作完成,pdf应该更小,因此是时候继续了
set oldSize to text item 1 of (do shell script "du " & quoted form of ShrinkPDF)
set newSize to text item 1 of (do shell script "du " & quoted form of ShrinkPDF)
do shell script "open -a " & quoted form of ("/Applications/Lightweight PDF.app") & " " & quoted form of ShrinkPDF
set timer to 0
repeat while newSize = oldSize and timer < 6
set newSize to text item 1 of (do shell script "du " & quoted form of ShrinkSize)
delay 1
set timer to timer + 1
end repeat
if newSize = oldSize then
tell application "Lightweight PDF"
activate
end tell
display dialog "This is taking a while maybe you want to quit manually..."
end if
tell application "Lightweight PDF"
quit
end tell
将oldSize设置为的文本项1(使用shell脚本“du”并引用ShrinkPDF格式)
将newSize设置为的文本项1(使用shell脚本“du”并引用ShrinkPDF格式)
执行shell脚本“open-a”和引用的(“/Applications/Lightweight PDF.app”)表单以及引用的ShrinkPDF表单
将计时器设置为0
在newSize=oldSize且计时器<6时重复
将newSize设置为的文本项1(执行shell脚本“du”并引用ShrinkSize格式)
延迟1
将定时器设置为定时器+1
结束重复
如果newSize=oldSize,则
告诉应用程序“轻量级PDF”
激活
结束语
显示对话框“这需要一段时间,您可能想手动退出…”
如果结束
告诉应用程序“轻量级PDF”
退出
结束语
你知道如何让脚本等待PDF压缩吗
使用AppleScript时,确实不需要使用do shell script
命令来打开PDF轻量级并处理PDF文件
下面的示例AppleScript代码将打开PDF Lightweight并处理目标PDF文件,在完成文件处理前,再加上几秒钟,不会继续处理剩余的代码:
将此pdf设置为“/path/to/filename.pdf”
告诉应用程序id“com.enoughpepper.lightweightpdf”
打开此PDF的引用表单
退出
结束语
--#放置在此处的代码在
--#PDF文件已完成处理。
如果出于某种原因,您想使用
do shell script
命令打开PDF轻量级并处理PDF文件
下面的示例AppleScript代码将打开PDF轻量级并处理目标PDF文件,并且在完成文件处理之前不会继续处理剩余代码:
将此pdf设置为“/path/to/filename.pdf”
将shellCmd设置为——
“ps-eo%cpu,命令| awk'/[L]lightweight PDF/{print int($1)}”
执行shell脚本——
“open-j-b'com.enoughpepper.lightweightpdf'&”
space&thisPDF的引用表格
延迟2
当(do shell脚本shellCmd)大于0时重复此操作
延迟1
结束重复
告诉应用程序id“com.enoughpepper.lightweightpdf”退出
--#放置在此处的代码在
--#PDF文件已完成处理。
在示例AppleScript代码的这种形式中,它确定应用程序已完成处理PDF文件,因为它不再消耗CPU周期。换句话说,处理完文件后,
do shell script
命令返回0。非常感谢!我尝试了您的第一种方法,但对我来说,“OpenQuotedFormofThisPDF”似乎找不到文档路径,“OpenPOSIXFileAttachment1”找到了文件,但没有压缩它。(我知道压缩它是可能的,因为当我将filr拖放到轻量级时,它会工作)