advice on the flow of the script
advice on the flow of the script
- Subject: advice on the flow of the script
- From: "Brandon Carpenter" <email@hidden>
- Date: Tue, 16 Jan 2001 08:21:35 -0600
I have a script that I would like to add some User Interface
elements too. My idea is simple. Put a Cd in and have a script
running that will find the CD, start SoundJam and place the
track listing in the convert window and start converting the
tracks. The user would input the UPC number, then a Jewel Case number,
then a Disk number. Then get the track numbers and rename the
file (after conversion) to the full name like so:
12345678912.01.01.001 doing the same to each track on the CD
until finished.
I am having difficultly with my own script about where the
conceatation of the file name to include the track number, should occur.
Could anyone give some advice on the flow of the script
below and some pointers on the Handlers to accomplish
this task? Any advice is welcome
Script Portions I have completed
*********************
-- Global to get Our Folder to Watch
global gOurFolder
main()
on main()
setgOurFolder to my folderPathOf(path of me)
-- Then we do any of the extract commands
set user_done to false
repeat while user_done is false
try
set user_done to extract_all_tracks()
on error
-- Do nothing. The try is just here to catch the stupid
"Cancel" button
from the second dialog.
end try
end repeat
end main
on extract_all_tracks()
-- Sets the Output Folder for the Extracted files
set fullWave to gOurFolder --choose folder with prompt "Choose Output
Folder"
-- set Track to be ripped to nothing
set tracksToRip to ""
-- sets the Audio CD to Nothing
set audioCD to ""
tell application "Finder"
activate
-- Looks for a CD by an ejectable disk and the name "Audio"
set diskList to every disk whose (ejectable is true)
repeat with i in diskList
if the name of i starts with "Audio" then
set audioCD to i
exit repeat
end if
end repeat
-- Displays if no CD
if audioCD = "" then
display dialog "No audio CD in CD Player"
return
else
set eject_the_disk to false
if eject_the_disk is true then
eject (every disk whose (ejectable is true))
return
else
-- set the track list and launch SoundJam to Rip Tracks
set trackList to {audioCD} as alias
tell application "SoundJam? MP"
activate
add trackList to converter window 1
--convert
end tell
end if
end if
end tell
end extract_all_tracks
on check_for_busy()
tell application "BarbaBatch v3"
set areWeDone to busy
if (busy) then
return
end if
end tell
end check_for_busy
on ask_for_cd_info()
set the_upc to enter_upc()
if the_upc is not "Quit" then
set the_jc_num to enter_jewel_case_num()
if the_jc_num is not "" then
set the_disk_num to enter_disk_num()
if the_disk_num is not "" then
--make statements to get the
--UPC & JC_Num & Disk_Num
--to conceatnate to the track numbers
return the_upc
end if
end if
else
if the_upc is "Quit" then
end if
end if
return ""
end ask_for_cd_info
-- Here's a simple UI for getting a UPC
on enter_upc()
set dialog_result to display dialog "CD Scanner" & return & return &
"Please enter a UPC:" default answer "" buttons {"Quit", "OK"} default
button "OK"
if button returned of dialog_result is "OK" then
set the_upc to (text returned of dialog_result)
try
-- If it passes this test, it's all digits.
--If not, it causes an error and we fall into the on error
handler.
set test_var to (the_upc as real)
-- Now make sure it's 11 digits long.
if length of the_upc is 11 then
return the_upc
else
error number -1
end if
on error
display dialog "A valid UPC contains 11 digits." buttons
{"OK"} default
button "OK" with icon "Stop"
end try
else
return "Quit"
end if
return ""
end enter_upc
-- Here's a simple UI for getting a jewel case number.
on enter_jewel_case_num()
set dialog_result to display dialog "Please enter a jewel case
number:"
default answer "1" buttons {"Cancel", "OK"} default button "OK"
if button returned of dialog_result is "OK" then
set the_jc_num to (text returned of dialog_result)
try
-- If it passes this test, it's all digits.
--If not, it causes an error and we fall into the on error
handler.
set the_jc_num to (the_jc_num as integer)
-- Now make sure it's between 1 and 99.
if (the_jc_num > 0) and (the_jc_num < 100) then
return the_jc_num
else
error number -1
end if
on error
display dialog "The jewel case number must be a number
between 1 and
999." buttons {"OK"} default button "OK" with icon "Stop"
end try
end if
return ""
end enter_jewel_case_num
-- Here's a simple UI for getting a disk number.
on enter_disk_num()
set dialog_result to display dialog "Please enter a disk number:"
default
answer "1" buttons {"Cancel", "OK"} default button "OK"
if button returned of dialog_result is "OK" then
set the_disk_num to (text returned of dialog_result)
try
-- If it passes this test, it's all digits.
--If not, it causes an error and we fall into the on error
handler.
set the_disk_num to (the_disk_num as integer)
-- Now make sure it's between 1 and 99.
if (the_disk_num > 0) and (the_disk_num < 100) then
return the_disk_num
else
error number -1
end if
on error
display dialog "The disk number number must be a number
between 1 and
999." buttons {"OK"} default button "OK" with icon "Stop"
end try
end if
return ""
end enter_disk_num
-- Returns the folder given a file path
--
on folderPathOf(filePath)
set reversedFilePath to (reverse of characters of (filePath as text)
as
text)
set theOffset to (length of reversedFilePath) - (offset of ":" in
reversedFilePath)
return (characters 1 thru theOffset of (filePath as text)) & ":" as
text
end folderPathOf