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