Solution:
Thank you for the feedback, and you were right—there was no need to divide the duration
by 1000. The duration
property in AppleScript for the Music app returns the time in seconds, not milliseconds.
Here is the updated and working AppleScript:
tell application "Music"
set selectedTracks to selection
repeat with aTrack in selectedTracks
-- Get the duration of the track (in seconds, no need to divide by 1000)
set trackDuration to duration of aTrack
-- Set the start time to 10 seconds
set start of aTrack to 10
-- Set the stop time 10 seconds before the end
set finish of aTrack to (trackDuration - 10)
end repeat
end tell
Changes:
- Removed the division by 1000, as the
duration
is already returned in seconds. - The
start
andfinish
times are set directly using seconds.
This script works perfectly now! Thanks again for pointing out the mistake.
Let me know if you need any further edits before posting!