I can’t believe how hard this is - I know four other languages and I’m stuck on a freaking filehandle.
My script eventually comes up with a filepath, the kind with the colons in it.
I want to test it either for its file extension or file type.
set theAttachment to item theAttachmentIndex of theAttachments
set theAttachmentFileName to name of theAttachment
set attFile to "tmp:" & theAttachmentFileName
save theAttachment in attFile
--set aFile to attFile as file
--set theFile to attFile as file specification
the file specification one works, but it doesn’t give me what I want. The file one doesn’t work. And getting info from either hasn’t been fruitful.
What I eventually want to do is test to see if the extension is aiff, and if it is, call afconvert to convert the file to a CAF file. But first I need to know how to get a file object from a file path. Can anyone help?
.
set theAttachment to item theAttachmentIndex of theAttachments
set theAttachmentFileName to name of theAttachment
set attFile to "tmp:" & theAttachmentFileName
save theAttachment in attFile
set aFile to attFile as alias
set Ex to file extension of (info for aFile)
if Ex is "aiff" then
-- do something
end if
Sorry about that, yes, this is an applescript that is called from Mail.app to, among other things, extract attachments from a mail message. I have an iPhone app that mails a voice recording to me, and then I want this rule to extract the voice recording and do something else with it.
However, I experimented with the file path and when prepending a volume it wouldn’t save. Since it’s saving in /tmp I thought that would be sufficient.
At any rate, when I reconstruct the path to prepend a Volume, it still isn’t working:
set theAttachments to mail attachments of the theMessage
set theAttachmentCount to count of theAttachments
repeat with theAttachmentIndex from 1 to theAttachmentCount
set theAttachment to item theAttachmentIndex of theAttachments
set theAttachmentFileName to name of theAttachment
set attFile to "tmp:" & theAttachmentFileName
save theAttachment in attFile
set filePath to "Juggernaut:tmp:" & theAttachmentFileName
set aFile to filePath as alias
set Ex to file extension of (info for aFile)
It cannot work, because you’re going to save the attachment to a non existing path
.
set theAttachments to mail attachments of the theMessage
set theAttachmentCount to count of theAttachments
repeat with theAttachmentIndex from 1 to theAttachmentCount
set theAttachment to item theAttachmentIndex of theAttachments
set theAttachmentFileName to name of theAttachment
set filePath to "Juggernaut:tmp:" & theAttachmentFileName
save theAttachment in filePath
set aFile to filePath as alias
set Ex to name extension of (info for aFile)
.