[applescript] check bestandsnaam & timer

Pagina: 1
Acties:

  • desmodus
  • Registratie: Februari 2001
  • Laatst online: 17-07-2023
Hoi,

Ik ben bezig om een Applescript te schrijven dat met onze urenregistratie werkt. Maar mijn scripting kennis houdt hier een beetje op, en hoop dat iemand mij hier weer in de goede richting kan wijzen.
Hier een korte uitleg wat het script gaat doen:
Het urenregistratie pakket creeert op een server, in een userfolder een bestand (yyyymmddHHMM). Het HHMM gedeelte van het bestand is het aantal geboekte uren, en de rest is van de betreffende dag. Het script moet dus checken of HHMM hoger of gelijk is aan 0800, en yyyymmdd de dag van gister is.

Ook ben ik op zoek naar een goed in te stellen timer die ook op IntelMacs werkt.

Hieronder mijn eerste stappen in de wereld die AppleScript heet.

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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


Dus mocht iemand tijd hebben om mij wat te helpen, of de juiste richting op te sturen... erg graag.

Thanks!