Created
December 17, 2024 14:01
-
-
Save kouichi-c-nakamura/cb8cf8654517ce848832561da8340642 to your computer and use it in GitHub Desktop.
AppleScript to set a timer to lock the screen of a Mac
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Prompt user to enter the delay time in minutes | |
display dialog "停止までの時間を分単位で入力してください:" default answer "30" | |
set delayMinutes to text returned of result as integer | |
-- Convert minutes to seconds and wait | |
set delaySeconds to delayMinutes * 60 | |
delay delaySeconds | |
-- Show a notification when the music starts playing | |
display notification "もうすぐ時間です" | |
-- Ensure the volume is not muted and is at a reasonable level | |
set volume output volume 50 -- set to 50%, adjust as necessary | |
-- Play the MP4 file | |
set filePath to "music_file.m4a" -- Replace with the full path to your MP4 file | |
set afplayPID to do shell script "nohup afplay " & quoted form of filePath & " > /dev/null 2>&1 & echo $!" | |
-- Wait for 10 seconds-- not working as expected | |
delay 15 | |
-- Stop playback | |
-- Find and kill the afplay process to stop the audio | |
do shell script "kill " & afplayPID | |
-- Lock the screen | |
do shell script "osascript -e 'tell application \"System Events\" to keystroke \"q\" using {control down, command down}'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment