|
|
AppleScript to rename received faxes?
|
|
|
|
Mac Elite
Join Date: Feb 2001
Location: Houston, Texas
Status:
Offline
|
|
One of the things my server does is receive faxes using the built-in functionality of Mac OS X Server 10.4. When a fax comes in, it creates a PDF with a name of "FAX from ##########.pdf", where the ###s represent the CallerID phone number. What I would like to do is have the incoming files be renamed to "Fax on [date & time] from [CallerID].pdf", so that a date/time stamp is placed on the file.
The reason I want to do this is that I've had some users move the faxes to their own folders and accidently replace files that had the same name. I know that Mac OS X has Folder Actions, so I figure there should be an AppleScript that does this, but I don't know anything about AS.
Thanks in advance for any help.
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Feb 2001
Location: Houston, Texas
Status:
Offline
|
|
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Apr 2003
Location: Hong Kong
Status:
Offline
|
|
I am in the same boat as you, my problem is almost all the faxes I receive have no CallerID, which causes headaches when 10-20 faxes arrive together in a short time.
|
|
|
|
|
|
|
|
|
Professional Poster
Join Date: Oct 2001
Location: London
Status:
Offline
|
|
Here you go - let me know if this works.
If you don't want the Growl notifications you can comment out any "my notify()" lines and delete the "to notify()" subroutine.
Code:
property growlRegistrationName : "Fax Folder Watcher AppleScript"
property GrowlNotificationName : "Incoming Fax"
property GrowlNotificationTitle : "Incoming Fax"
property FaxFilenameprefix : "FAX "
to notify(noteText)
-- display dialog ("notify(" & noteText & ")!")
-- Notify using Growl
tell application "GrowlHelperApp"
notify with name GrowlNotificationName title GrowlNotificationTitle description (noteText as text) application name growlRegistrationName
end tell
end notify
-- subroutine to replace chars in a string
on replace_chars(this_text, search_string, replacement_string)
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
return this_text
end replace_chars
-- Folder Action stuff
on adding folder items to targetFolder after receiving DroppedItems
-- Register with Growl
tell application "GrowlHelperApp"
set myAllNotesList to {GrowlNotificationName}
register as application growlRegistrationName all notifications myAllNotesList default notifications {GrowlNotificationName} icon of application "Finder"
end tell
repeat with currentFile in DroppedItems
tell application "Finder"
set droppedFileName to the name of currentFile
set droppedFileInfo to info for currentFile
-- my notify("Processing File: " & droppedFileName)
if droppedFileName starts with FaxFilenameprefix then
-- rename the file
my notify("Possible new fax detected")
-- get the callerID and file extension of the new file
copy (characters (count of FaxFilenameprefix) thru (count of characters of droppedFileName) of droppedFileName) to callerIDAndExtension
-- my notify(callerIDAndExtension)
-- Get the date & time as a string
set now to current date
set dateStampString to (date string of now & " - " & time string of now) as string
-- my notify(dateStampString)
-- We have to alter the start of the filename
-- otherwise the file will appear to be a new file - and this script will run again causing an infinite loop.
set newFaxFileName to (" " & FaxFilenameprefix & "on " & dateStampString & callerIDAndExtension) as string
-- Times have colons in - which is a no-no in filenames.
set newFaxFileName to my replace_chars(newFaxFileName, ":", ";")
-- my notify("New filename: " & newFaxFileName)
-- Rename the actual file
set the name of currentFile to newFaxFileName
my notify("Fax Renamed")
else
-- my notify("File NOT a fax")
end if
end tell
end repeat
end adding folder items to
|
|
|
|
|
|
|
|
|
Professional Poster
Join Date: Oct 2001
Location: London
Status:
Offline
|
|
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Feb 2001
Location: Houston, Texas
Status:
Offline
|
|
I'll try it tomorrow. This is an Applescript right? I just need to use AS Studio and save it?
|
|
|
|
|
|
|
|
|
Professional Poster
Join Date: Oct 2001
Location: London
Status:
Offline
|
|
It's an AppleScript, yes - but you need to paste in into Script Editor instead of AS Studio.
Save it as an .scpt into ~/Library/Scripts/Folder Action Scripts/
Then, using the Finder, go to the folder where faxes are received and right click in it - choose "attach folder action", then choose the script from the menu.
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Feb 2001
Location: Houston, Texas
Status:
Offline
|
|
It's asking for a GrowlHelper application when I try to save the scpt file. I assume it has something to do with your signature but that link's not working for me right now.
|
|
|
|
|
|
|
|
|
Professional Poster
Join Date: Oct 2001
Location: London
Status:
Offline
|
|
try this version of the script - I've removed all Growl notifications.
Code:
property FaxFilenameprefix : "FAX "
-- subroutine to replace chars in a string
on replace_chars(this_text, search_string, replacement_string)
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
return this_text
end replace_chars
-- Folder Action stuff
on adding folder items to targetFolder after receiving DroppedItems
repeat with currentFile in DroppedItems
tell application "Finder"
set droppedFileName to the name of currentFile
set droppedFileInfo to info for currentFile
if droppedFileName starts with FaxFilenameprefix then
-- rename the file
-- get the callerID and file extension of the new file
copy (characters (count of FaxFilenameprefix) thru (count of characters of droppedFileName) of droppedFileName) to callerIDAndExtension
-- Get the date & time as a string
set now to current date
set dateStampString to (date string of now & " - " & time string of now) as string
-- We have to alter the start of the filename
-- otherwise the file will appear to be a new file - and this script will run again causing an infinite loop.
set newFaxFileName to (" " & FaxFilenameprefix & "on " & dateStampString & callerIDAndExtension) as string
-- Times have colons in - which is a no-no in filenames.
set newFaxFileName to my replace_chars(newFaxFileName, ":", ";")
-- Rename the actual file
set the name of currentFile to newFaxFileName
end if
end tell
end repeat
end adding folder items to
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Feb 2001
Location: Houston, Texas
Status:
Offline
|
|
Ok I took the second script and saved it to ~/Library/Scripts/Folder Actions Scripts as faxrename.scpt. I then went to a test folder and configured it to use that FA, and copied a FAX file into the folder. Nothing happened.
|
|
|
|
|
|
|
|
|
Professional Poster
Join Date: Oct 2001
Location: London
Status:
Offline
|
|
hmmm - OK, that's odd. I just tried it with some old fax on my machine and it worked (standard developers get-out clause.)
we're going to have to do some remote bug hunting, which can be tricky.
In order to find out where the script is failing we need to get the script to tell us where it's failing on your machine.
If you don't mind I'd like you to do the following:
Download the following script (it's basically the same, but with a whole load of applescript 'display dialog' commands - it will report what it's doing via dialogs, and we can tell where the error occurs.)
Use this script instead of the older one for the folder action script - and post what it tells you when you copy the fax:
http://www.diggory.net/grazing/renam...layDialogs.zip
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Feb 2001
Location: Houston, Texas
Status:
Offline
|
|
Originally Posted by Diggory Laycock
hmmm - OK, that's odd. I just tried it with some old fax on my machine and it worked (standard developers get-out clause.)
we're going to have to do some remote bug hunting, which can be tricky.
In order to find out where the script is failing we need to get the script to tell us where it's failing on your machine.
If you don't mind I'd like you to do the following:
Download the following script (it's basically the same, but with a whole load of applescript 'display dialog' commands - it will report what it's doing via dialogs, and we can tell where the error occurs.)
Use this script instead of the older one for the folder action script - and post what it tells you when you copy the fax:
http://www.diggory.net/grazing/renam...layDialogs.zip
Just for grins, I just put the original faxrename.scpt into /Library... (instead of ~/Library...) and it works now. Seems it needed to be under the main Library instead of under the one in my Home folder.
Good job with your comments. I didn't like the space at the beginning of the file, so I changed that part of the script to be "Received " so the renamed file looks like: "Received FAX on Tuesday, October 10, 2006 - 20;41;17 from 2125551212.pdf"
Now, that's a really long file name because of the verbose date. Anyway to have the date formatted in YYYY-MM-DD format?
|
|
|
|
|
|
|
|
|
Professional Poster
Join Date: Oct 2001
Location: London
Status:
Offline
|
|
Glad it works now. Good idea with the changing of the leading space.
re: date - The date format is the default one for applescript - it should be relatively easy to change:
Swap the line:
Code:
set dateStampString to (date string of now & " - " & time string of now) as string
to
Code:
set dateStampString to (year of now & "-" & (month of now as integer) & "-" & (day of now) & " - " & time string of now) as string
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Feb 2001
Location: Houston, Texas
Status:
Offline
|
|
Perfect. Thanks so much for all your help!
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Forum Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|