Blogitter

INJECT

append delete Bot 78
%

-- Save a backup of the current file
-- Copyright under GPL by Mark Grimes
-- Saving with '\scs' in the filename creates Shortcut: Crtl+Shift+S

tell application "Microsoft Excel"
	set macPath to get full name of (get properties of active workbook)
	set curPath to my posix_path(macPath)
	set cmdStatus to do shell script ¬
		"perl -MFile::Copy -MFile::Basename -MFile::Spec -e' " & ¬
		"$f=qq{" & curPath & "}; " & ¬
		"$d = File::Spec->catdir(dirname($f),q{Backup});" & ¬
		"mkdir $d unless -d $d;" & ¬
		"$b = File::Spec->catfile($d,basename($f)); " & ¬
		"$i=1;" & ¬
		"do {$s = sprintf( qq{%03d}, $i++); $b=~s/(?:.\d{3})?.(xlsx?)$/.$s./; }" & ¬
		"  while( -e $b );" & ¬
		"copy $f, $b or die qq{Error copying $f to $b: $!};" & ¬
		"print qq{Backed up last saved version to: $b};" & ¬
		" ' "
	display dialog cmdStatus
end tell

-- From: http://www.macosxhints.com/article.php?story=20011030193449870
-- Thanks!
on posix_path(mac_path)
	set mac_path to (mac_path as text)
	set root to (offset of ":" in mac_path)
	set rootdisk to (characters 1 thru (root - 1) of mac_path)
	tell application "Finder"
		if (disk (rootdisk as string) is the startup disk) then
			set unixpath to "/" & (characters (root + 1) thru end of mac_path)
		else
			set unixpath to "/Volumes:" & mac_path
		end if
	end tell
	set chars to every character of unixpath
	repeat with i from 2 to length of chars
		if item i of chars as text is equal to "/" then
			set item i of chars to ":"
		else if item i of chars as text is equal to ":" then
			set item i of chars to "/"
		else if item i of chars as text is equal to "'" then
			set item i of chars to "\'"
		else if item i of chars as text is equal to "\"" then
			set item i of chars to "\" & "\""
		else if item i of chars as text is equal to "*" then
			set item i of chars to "\*"
		else if item i of chars as text is equal to "?" then
			set item i of chars to "\?"
		else if item i of chars as text is equal to " " then
			set item i of chars to "\ "
		else if item i of chars as text is equal to "\" then
			set item i of chars to "\\"
		end if
	end repeat
	return every item of chars as string
end posix_path

%

Reply RSS

Reply

(Leave this as-is, it’s a trap!)

There is no need to “Register”. Just enter the same Name + Password of your choice every time.

Use Format Text to add links, quotes, bold, italic and more. You can also upload images or videos or archived web pages or multicontent or use any upload website.

Moderators: Blogitter Team

  1. Home
  2. » Pastebin

ABOUT :: BLOGITTER NEWS :: FEEDBACK :: MULTILINGUAL :: FORMAT TEXT :: RSS FEEDS :: REQUEST NEW CATEGORY :: REPORT ABUSE :: HELP :: TERMS OF USE :: CONTACT