Save file as current date

I am using a program called QLab, and I would like to build an applescript that would save the file as the current date. The ultimate goal is versioning, so I have a different file for each days work. Any help would be much appreciated.

Hello.

Maybe this will suit you:


set version_number to 0
set f to (current date)'s date string
# you can  append a version number  like this: set f to f & "-" & version_number

Assuming you have set the former when you saved the file the first time, during the next times
you can construct a new filename like this, assuming this is run from a script while the QLab app is active:

tell current application
	set f to name of its first document
end tell
set version_number to last word of f as integer
set version_number to version_number + 1
tell (a reference to text item delimiters)
	set oldtids to contents
	set contents to "-"
	set tmplist to text items of f
	set item -1 of tmplist to version_number
	set f to tmplist as text
	set contents to oldtids
end tell

There are more things to saving your file with the new versioned file-name, but I hope this is a step in the right direction. :slight_smile:

Edit

I elaborated a little on the two above, and made the stem of a script for creating a new labreport:

property script_title : "New Lab report"
set dts to (current date)'s date string
set labrepname to ""
tell current application
	activate
	set nm to text returned of (display dialog "Please enter name for new lab report dated " & dts & ":" default answer "" with title my script_title with icon 1)
	if nm is "" then return
	set version_number to 0
	set labrepname to nm & " " & dts & "-" & version_number
	display dialog "Your labreport will get the name:" & labrepname & linefeed & " once saved." with title my script_title with icon 1
end tell

And create new lab report version:

property script_title : "New Lab report-version"
tell current application
	set labrepname to name of first document
	
	set version_number to last word of labrepname as integer
	set version_number to version_number + 1
	tell (a reference to AppleScript's text item delimiters)
		set oldtids to contents
		set contents to "-"
		set tmplist to text items of labrepname
		set item -1 of tmplist to version_number
		set labrepname to tmplist as text
		set contents to oldtids
	end tell
	display dialog "Your labreport will get the name:" & labrepname & linefeed & " once saved." with title my script_title with icon 1
	
end tell

Maybe they won’t work, but should serve well as a starting point QLab has a rather stiff price for testing scripts. :slight_smile:

Thank you very much! I will certainly look into it. QLab does have a free version, which is what I am using.

Hello.

Could you please provide a link, what I get up in my browser, is something that you can hire for 4 dollars a day as the cheapest alternative. :slight_smile:

Here you go! http://figure53.com/downloads/QLab.zip

Thank you! :slight_smile:

Unfortunately, I can’t run it as it requires Mountain Lion to run.

I’d recommend using a yyyy-mm-dd format for the date, as this will sort by name as the same as by date.

This just saves the front workspace to the desktop with a date-based name. No “versioning”.

tell (current date) to ¬
	tell (its year) * 10000 + (its month) * 100 + (its day) as text to ¬
		set ISO_date to text 1 thru 4 & "-" & text 5 thru 6 & "-" & text 7 thru 8

-- Or, if you want to chance a method which may not work in the future:
-- set ISO_date to text 1 thru 10 of ((current date) as «class isot» as string)

tell application "QLab"
	save workspace 1 in file ((path to desktop as text) & ISO_date & ".cues")
end tell

Your version worked perfectly Nigel, thanks! Now if I try and save it somewhere different than the desktop, it doesn’t like it. Here’s what I’m using

tell (current date) to ¬
	tell (its year) * 10000 + (its month) * 100 + (its day) as text to ¬
		set ISO_date to text 1 thru 4 & "-" & text 5 thru 6 & "-" & text 7 thru 8

tell application "QLab"
	set savePath to "/Users/Jason/Documents/"
	save workspace 1 in file (savePath & ISO_date & ".cues")
end tell

Which gives me the error:

Even though I know I have permission to write to that directory. I clearly need to do some more reading about applescript.

Hi,

just replace desktop with documents folder


tell application "QLab"
   save workspace 1 in file ((path to documents folder as text) & ISO_date & ".cues")
end tell

The default file path type of AppleScript is HFS (colon separated).
Only a few apps accept POSIX paths

It’s also worth noting that, according to the latest AS release notes, sandboxed apps can’t use bare paths of any kind, only proper specifiers. QLab doesn’t appear to be sandboxed, but it seems a good idea for scripters to get back into the habit of using full specifiers anyway:

file "HFS:path:to:file"
alias "HFS:path:to:file"
POSIX file "/POSIX/path/to/file"

Good to know, then I guess this idiom is much easier to use all of the time, than trying to figure out who’s sandboxed.

Thanks. :slight_smile: