AppleScript 编程/示例程序/在全屏模式下运行 QuickTime
外观
< AppleScript 编程 | 示例程序
复制脚本,将其粘贴到 ScriptEditor 中,并保存为应用程序。
当您将电影文件拖放到应用程序上时,它将首先检查是否有多个文件被拖放到应用程序中。如果有多个文件,它会提醒您并结束程序。否则,它将打开 QuickTime 并将其置于最前面,在 QT 中打开拖放的电影,使其全屏并开始播放。
如果您双击启动应用程序,它只会给您一个对话框并退出。请注意,此脚本检查了它无法处理的情况,并让用户知道。
- 它检查了没有电影要播放的情况,并提醒用户,而不是什么都不做,对用户来说很神秘。
- 它检查了多个电影的情况,并提醒用户只能播放一部电影,并播放第一部电影
(*
This script is an example of how to build an application using
AppleScript.
This application is useful for teaching AppleScript but actually
You can open movie files in the Finder and the Finder would
tell "QuickTime Player.app" to open the movies. This script
gives you an idea of how Finder does that, by sending messages
to "QuickTime Player.app".
Copy the script, paste it into ScriptEditor, and save as an application.
When you drop a movie-file on the application, it'll first check if there is more than
one file dropped into the application. If more than one, then it'll note about it and end
the program. Else, it'll open QuickTime and bring it on front, open the dropped movie in QT,
make it full screen and start playing it.
If you open the application without opening any files, the application will
just give you a alert and quit. You either have to open the movie file by dragging
it onto this application or configure your Mac to open movie files with this app.
-- This handler is called if this application is opened without any documents being opened with it.
-- In this case, this application will alert the user and quit
on run
display dialog "To run this application, you must open a movie document with it such as dragging and dropping a movie file onto this application." buttons {"OK"} ¬
default button 1 with icon stop
end run
-- This handler is called when movies are opened along with this application
-- In this case, this application will play the first movie
on open (theseFiles)
try
-- alert the user that more than one file was opened and that this application can only have QuickTime play one of them
if (count (theseFiles)) > 1 then
display dialog ¬
"This program can only play one movie. Only the first movie will be played." buttons ¬
{"OK"} default button 1 with icon 1
end if
-- get the first movie from the file(s) opened
set thisMovie to item 1 of theseFiles
-- have QuickTime Player play the movie
tell application "QuickTime Player"
-- make sure that QuickTime Player is open and is the frontmost application
activate
-- open the first movie
open thisMovie
-- play the movie
play
end tell
on error eMessage number eNumber
-- if there were any errors, then display the error message and error number
display alert "Error: " & eMessage & return & return & (eNumber as text)
end try
end open