xtrmn8ngangl

Q: Logging Hours Worked

Hello,

 

I'm new to this, but I would like to learn to write an applescript that would carry out a very specific work flow.

 

Ideally this is what would happen.

 

run the script

dialog opens asking me to "Check In" or "Check Out"

 

If I choose "Check In"

fill a specified "Numbers" table cell with the current date and time.

(each time the script runs filling in the next row of the spread sheet).

&

Launch my application to begin work (Avid Media Composer).

 

If I choose "Check Out"

fill a specified "Numbers" table cell with the current date and time.

(the next column from the previous "Check In").

&

Create a copy(zip archive) of my Avid project folder.

 

If anyone knows of a tutorial or something that I could study that would be great.

Just looking for a lead...

 

I can launch my app and create the archive in automator, but was hoping to log my hours somehow as well.

 

thanks for the help,

Aaron

 


MacBook Pro, Mac OS X (10.6.6), 4gb ram

Posted on Nov 17, 2013 5:41 PM

Close

Q: Logging Hours Worked

  • All replies
  • Helpful answers

Page 1 Next
  • by Pierre L.,

    Pierre L. Pierre L. Nov 18, 2013 1:26 PM in response to xtrmn8ngangl
    Level 5 (4,484 points)
    Nov 18, 2013 1:26 PM in response to xtrmn8ngangl

    Hi Aaron,

     

    Mutatis mutandis, the following script should do what you are asking for. I’ve used TextEdit instead of Avid Media Composer, and the folder “My folder” instead of your Avid project folder.

     

    You might want to run the script from the AppleScript Editor window, using a new Numbers document as a spreadsheet.

     

     

    set theFolder to POSIX file "/Users/pierre/Desktop/My folder" as alias

    set theSpreadSheet to POSIX file "/Users/pierre/Desktop/My spreadsheet.numbers" as alias

     

    -- Dialog asking to "Check In" or "Check Out"

    display dialog "Some message." buttons {"Cancel", "Check In", "Check Out"} cancel button 1 with icon 1 with title "Some title"

    set theButton to button returned of result

     

    tell application "Numbers ’09"

        -- open the spreadsheet (a Numbers document):

        launch

        if not (exists (document 1 whose path is theSpreadSheet)) then

            open theSpreadSheet

        end if

     

        -- fill in the appropriate cell:

        tell front document

            tell table 1 of sheet 1

                set theCell to cell 1 of column "B" whose (name is not "B1") and (value = 0)

                if theButton is "Check In" then

                    set checkIn to true

                    set value of theCell to (current date) as text -- check-in date & time

                else

                    set checkIn to false

                    set theRow to address of row of theCell

                    set theCell to cell (theRow - 1) of column "C"

                    set value of theCell to (current date) as text -- check-out date & time

                end if

            end tell

        end tell

        save

    end tell

     

     

    if checkIn then

        tell application "TextEdit" to activate -- launch the application to begin work

    else

        tell application "TextEdit" to quit -- quit the application

     

        -- Create a copy (zip archive) of your Avid project folder.

        tell application "Finder"

            activate

            select theFolder

        end tell

        tell application "System Events" to tell process "Finder" to click menu item "Compress" of menu 1 of menu bar item "File" of menu bar 1

    end if

     

     

    To learn AppleScript, have a look at Starting out with AppleScript.

     

    Hope it can help.

  • by xtrmn8ngangl,

    xtrmn8ngangl xtrmn8ngangl Nov 18, 2013 2:04 PM in response to Pierre L.
    Level 1 (0 points)
    Nov 18, 2013 2:04 PM in response to Pierre L.

    wow very impressive.

    Thank you very much.

     

    I was able to swich my folders and application so it is running perfectly up until the last couple of lines...

    I get this error.

     

    error "System Events got an error: Can’t get menu item \"Compress\" of menu 1 of menu bar item \"File\" of menu bar 1 of process \"Finder\"." number -1728 from menu item "Compress" of menu 1 of menu bar item "File" of menu bar 1 of process "Finder"

     

    Do you know why this may be happening.

    My other question is is there a way to control where and how the zip is saved.

    I assume that is part of the error, the zip, but I dont know where to find it.

     

    Thanks a lot,

    Aaron

  • by Pierre L.,

    Pierre L. Pierre L. Nov 18, 2013 2:17 PM in response to xtrmn8ngangl
    Level 5 (4,484 points)
    Nov 18, 2013 2:17 PM in response to xtrmn8ngangl

    I get this error.

     

    error "System Events got an error: Can’t get menu item \"Compress\" of menu 1 of menu bar item \"File\" of menu bar 1 of process \"Finder\"." number -1728 from menu item "Compress" of menu 1 of menu bar item "File" of menu bar 1 of process "Finder"

     

    That may depend on your version of OS X. Can you tell me wich menu item of which menu, in your version of OS X, allows you to make a zip archive from the OS X Finder. Please give me the exact name of that menu item. Is that name in German or in English?

     

    Message was edited by: Pierre L.

  • by xtrmn8ngangl,

    xtrmn8ngangl xtrmn8ngangl Nov 18, 2013 3:35 PM in response to Pierre L.
    Level 1 (0 points)
    Nov 18, 2013 3:35 PM in response to Pierre L.

    Hello,

     

    I am in OS X version 10.8.5.

    To compress a file I would do I go to Edit -> Compress.

    I do not get to choose my save location when I select this.

     

     

    I would like to add a couple things that I will try on my own...(If i can't figure it out ill be sure to let you know, hahaha.)

     

    Adding a text field to the dialogue box(I saw a tutorial on this that I will try).

    when the button is pressed it would send the text to a respective cell if "check in" is clicked or "Check out".

    (would I be able to add a variable and reference that in a similar way as you did with the current date portion of the script? I would change the cell and column too.)

     

    Thanks, this is really great.

     

    Aaron

  • by Pierre L.,

    Pierre L. Pierre L. Nov 18, 2013 3:42 PM in response to xtrmn8ngangl
    Level 5 (4,484 points)
    Nov 18, 2013 3:42 PM in response to xtrmn8ngangl

    To compress a file I would do I go to Edit -> Compress.

     

    Then you should replace

     

        tell application "System Events" to tell process "Finder" to click menu item "Compress" of menu 1 of menu bar item "File" of menu bar 1

     

    with

     

        tell application "System Events" to tell process "Finder" to click menu item "Compress" of menu 1 of menu bar item "Edit" of menu bar 1

     

    Does it work ?

  • by Pierre L.,

    Pierre L. Pierre L. Nov 18, 2013 4:03 PM in response to xtrmn8ngangl
    Level 5 (4,484 points)
    Nov 18, 2013 4:03 PM in response to xtrmn8ngangl

    To compress a file I would do I go to Edit -> Compress.

    I do not get to choose my save location when I select this.

     

    By default, the zip archive is created in the same folder as the original file or folder. However, you could move it to another folder.

     

    For example, adding the following  line of code at the beginning of the script:


    set theDestinationFolder to POSIX file "/Users/pierre/Desktop/My archives" as alias


    and then changing the end of the script as follows:

     

    if checkIn then

        tell application "TextEdit" to activate -- launch the application to begin work

    else

        tell application "TextEdit" to quit -- quit the application

     

        -- Create a copy (zip archive) of your Avid project folder in the folder of your choice.

        tell application "Finder"

            activate

            select theFolder

            tell application "System Events" to tell process "Finder" to click menu item "Compress" of menu 1 of menu bar item "File" of menu bar 1

            delay 1 -- adjust if necessary

            move file (name of theFolder & ".zip") to folder theDestinationFolder with replacing

        end tell

    end if

     

    I can save the archive to the destination folder “My archives” (with replacing).



    Message was edited by: Pierre L. (one-second delay added)

  • by xtrmn8ngangl,

    xtrmn8ngangl xtrmn8ngangl Nov 18, 2013 4:17 PM in response to Pierre L.
    Level 1 (0 points)
    Nov 18, 2013 4:17 PM in response to Pierre L.

    Hello,

     

    I made a mistake the menu tab is in fact "File", and not "Edit"

    But both do not work. The error looks the same.

     

    I also tied to add this to the initial dialog

     

    display dialog "What will it be?" default answer "Project Name or Notes" buttons {"Cancel", "Check In", "Check Out"} cancel button 1 with icon 1 with title "Some title"

     

    set theAnswer to text returned of result

    set theButton to button returned of result

     

    but my result is an error.

     

    error "Can’t get button returned of \"Project Name or Notes\"." number -1728 from button returned of "Project Name or Notes"


     

    I wanted to then use theAnswer in a cell much in the same way you did the time...

     

    Thanks for your time and insight.

     

    Aaron

  • by Pierre L.,

    Pierre L. Pierre L. Nov 18, 2013 4:39 PM in response to xtrmn8ngangl
    Level 5 (4,484 points)
    Nov 18, 2013 4:39 PM in response to xtrmn8ngangl

    Let's begin with the easiest:

     

    set theButton to button returned of result

     

    cannot work because result is the result of the previous line, not the same result as the first one.

     

    Try this instead:

     

    set theResult to display dialog "What will it be?" default answer "Project Name or Notes" buttons {"Cancel", "Check In", "Check Out"} cancel button 1 with icon 1 with title "Some title"

     

    set theAnswer to text returned of theResult

    set theButton to button returned of theResult

     

     

    is

  • by Pierre L.,

    Pierre L. Pierre L. Nov 18, 2013 4:37 PM in response to xtrmn8ngangl
    Level 5 (4,484 points)
    Nov 18, 2013 4:37 PM in response to xtrmn8ngangl

    I made a mistake the menu tab is in fact "File", and not "Edit"

    But both do not work. The error looks the same.

     

    Try replacing

     

        tell application "System Events" to tell process "Finder" to click menu item "Compress" of menu 1 of menu bar item "File" of menu bar 1

     

    with

     

        tell application "System Events" to tell process "Finder" to click (menu item 1 of menu 1 of menu bar item "File" of menu bar 1 whose name begins with "Compress")

     

     

    If that still doesn't work, then try adding a short delay just before the above line of code, for instance:  delay 0.25

     

    Message was edited by: Pierre L.

  • by xtrmn8ngangl,

    xtrmn8ngangl xtrmn8ngangl Nov 18, 2013 4:44 PM in response to Pierre L.
    Level 1 (0 points)
    Nov 18, 2013 4:44 PM in response to Pierre L.

    We are so close, but I am still getting the error... The zips are being created.

     

    error "Finder got an error: Can’t get file \"Reciprocity.zip\"." number -1728 from file "Reciprocity.zip"

     

    Thanks,

    Aaron

  • by Pierre L.,

    Pierre L. Pierre L. Nov 18, 2013 4:47 PM in response to xtrmn8ngangl
    Level 5 (4,484 points)
    Nov 18, 2013 4:47 PM in response to xtrmn8ngangl

    I had edited my post in order to add a one-second delay before the line

     

            move file (name of theFolder & ".zip") to folder theDestinationFolder with replacing


    Have you added that delay too?

  • by xtrmn8ngangl,

    xtrmn8ngangl xtrmn8ngangl Nov 18, 2013 4:54 PM in response to Pierre L.
    Level 1 (0 points)
    Nov 18, 2013 4:54 PM in response to Pierre L.

    Yes I have that too.

     

    -- Create a copy (zip archive) of your Avid project folder in the folder of your choice.

              tell application "Finder"

      activate

      select theFolder

                        tell application "System Events" to tell process "Finder" to click (menu item 1 of menu 1 of menu bar item "File" of menu bar 1 whose name begins with "Compress")

      delay 1 -- adjust if necessary

      move file (name of theFolder & ".zip") to folder theDestinationFolder with replacing

              end tell

    end if

     

    i also tried delay 10, but not luck...

     

    Aaron

  • by xtrmn8ngangl,

    xtrmn8ngangl xtrmn8ngangl Nov 18, 2013 5:01 PM in response to xtrmn8ngangl
    Level 1 (0 points)
    Nov 18, 2013 5:01 PM in response to xtrmn8ngangl

    I was abe to figure out adding the result to the dialog box on my own!

    But I owe it to you... thanks!

     

    Aaron

  • by Pierre L.,

    Pierre L. Pierre L. Nov 18, 2013 5:04 PM in response to xtrmn8ngangl
    Level 5 (4,484 points)
    Nov 18, 2013 5:04 PM in response to xtrmn8ngangl

    i also tried delay 10, but not luck...

     

    My bad. I think I know where I made a mistake… I'll let you know as soon as I find a fix.

Page 1 Next