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

Reply
17 replies

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

opentheSpreadSheet

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.

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

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.

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

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

movefile (name of theFolder & ".zip") tofoldertheDestinationFolder with replacing

endtell

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)

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

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

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.

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


selecttheFolder

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


movefile (name of theFolder & ".zip") tofoldertheDestinationFolder with replacing

end tell

end if


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


Aaron

Nov 18, 2013 5:21 PM in response to xtrmn8ngangl

Change the last part 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

tell application "Finder"

activate

selecttheFolder

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")

end tell


-- Move the archive to the folder of your choice:

set theFolderPath to POSIX path of theFolder

set theArchive to POSIX file (text 1 through -2 of theFolderPath & ".zip")

tell application "Finder"

repeat until theArchive exists

end repeat

movetheArchivetofoldertheDestinationFolder with replacing

end tell

end if

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Logging Hours Worked

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.