PDA

View Full Version : AppleScript check filename




TheDesmodus
Jun 30, 2008, 09:26 AM
Hi,

I am having some trouble in creating an AppleScript that we need for hour registration here at work. We are using a system that can create a file each time someone 'books' their hours in the system.
What we want to create is the following:
The hour registration app creates a file (yyyymmddHHMM) on the server in a users folder. The HHMM is the number of hours and minutes booked by the user.
The script should check if the HHMM is higher then 08 hours and 00 minutes.
If it is, it should just quit. If it isnt it should chance the users network prefs location (but it should sudo it somehow, since users are locked out of that part of their system).
There is a 15 minute grace button, but I need to figure out how to make a 15 minute timer.

Is there anyone that can point me in the right direction again?

Cheers!



tell application "Finder"
activate
set scriptFolder to "Traffic:yada:yada:user"
if not (exists folder scriptFolder) then
try
mount volume "afp://192.168.0.16/traffic" as user name "user" with password "password"
close window (user)
on error
display dialog "There was an error mounting the Volume." & return & return & "The server may be unavailable at this time." buttons {"OK"} default button 1
end try
end if

-- set first 8 digits of the needed filename
set theDate to do shell script "date '+%Y%m%d'" as string
-- here I need to check if a filename beginning with theDate exists in this location, if not then do 'function display'
-- tricky part is that I also need to be able to exclude saturdays and sundays in the check, And for parttimers certain fixed days. I have no idea how to script this

-- here I need to check if the xx (position 9 and 10) in the filename (yyyymmddxxmm) is higher then the number 08.

-- if the xx are 08 or higher
do shell script "scselect 'work'"

-- if the xx are lower then 08 do the following
-- 'function display'
display dialog ("Your hours have not been filled in, you will be locked out of your system") buttons {"15 more minutes", "OK"} default button 2
if the button returned of the result is "15 more minutes" then
do shell script "scselect 'work'"
-- Unmount Traffic disk for security reasons
set remote_drives to ["Traffic"]
repeat with drive in remote_drives
set drive to "/Volumes/" & drive
do shell script "umount " &
quoted form of drive
end repeat
else
-- change System Preferences location
do shell script "scselect 'jail'"
end if
-- Insert 15 minute timer here, after 15 minutes re-run the script



-- Unmount Traffic disk for security reasons
set remote_drives to ["Traffic"]
repeat with drive in remote_drives
set drive to "/Volumes/" & drive
do shell script "umount " &
quoted form of drive
end repeat
end tell


-- Start screensaver
try
tell application id "com.apple.ScreenSaver.Engine" to launch
end try