Go Back   The macosxhints Forums > OS X Help Requests > AppleScript



Reply
 
Thread Tools Rate Thread Display Modes
Old 08-19-2010, 12:47 AM   #1
ChrisGraham
Prospect
 
Join Date: Aug 2010
Posts: 4
Making the filename - the file extension into a Variable.

Hey all, bit of a newb here with an interesting question....I run 10.6 and
I have tons of files called something like:

SomeonesEmailAddress@domain.com.WAV

I need a script that can copy the email address from the file, but not the extension and make it into a variable that I can use to make a new e-mail to send to individual.

I've tried with the code, but can't seem to get it to work without including the extension and have done extensive research but still can't figure it out.

tell application "Finder" to set theName to displayed name of item 1 of (get selection)

tell application "Mail"
set theMessage to make new outgoing message with properties {visible:true, subject:"Files", content:""}

tell theMessage
make new to recipient at end of to recipients with properties {address:theName}

end tell

end tell
ChrisGraham is offline   Reply With Quote
Old 08-19-2010, 06:50 AM   #2
fracai
MVP
 
Join Date: May 2004
Posts: 2,012
This thread looks like it's trying to achieve something similar. At least in the "strip extension" part anyway.
fracai is offline   Reply With Quote
Old 08-19-2010, 08:41 AM   #3
renaultssoftware
MVP
 
Join Date: Dec 2009
Location: Pembroke, Ontario
Posts: 2,051
Code:
set xx to "My untitled doc.txt"
set y to offset of "." in xx
set zz to (characters 1 thru (y - 1) of xx) as string
--result: "My untitled doc"
Modify that a bit, and wait a minute. If there are two periods, it won't work.

If they're all WAV files, you can use: characters 1 thru -5 of "This sucks.doc.wav" as string or similar.
__________________
Get Icon Creator and support me.
renaultssoftware is offline   Reply With Quote
Old 08-19-2010, 12:57 PM   #4
tw
Hall of Famer
 
Join Date: Apr 2007
Posts: 4,262
I always like text item delimiters for things like this:

Code:
tell application "Finder" to set theName to name of item 1 of (get selection)

set {oldTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "."}
set theName to (text items 1 thru -2 of theName) as text
set AppleScript's text item delimiters to oldTID

tell application "Mail"
	set theMessage to make new outgoing message with properties {visible:true, subject:"Files", content:""}
	tell theMessage
		make new to recipient at end of to recipients with properties {address:theName}
	end tell
end tell
__________________
Philosophy is a battle against the bewitchment of our intelligence by means of language. -LW-
tw is offline   Reply With Quote
Old 08-19-2010, 01:05 PM   #5
renaultssoftware
MVP
 
Join Date: Dec 2009
Location: Pembroke, Ontario
Posts: 2,051
Yeah, I pondered that but decided that this would be a bit simpler.

Accessing this website from an iPhone is impossible!
__________________
Get Icon Creator and support me.
renaultssoftware is offline   Reply With Quote
Old 08-19-2010, 01:09 PM   #6
tw
Hall of Famer
 
Join Date: Apr 2007
Posts: 4,262
Quote:
Originally Posted by renaultssoftware
Yeah, I pondered that but decided that this would be a bit simpler.

Accessing this website from an iPhone is impossible!

simpler, yes, but as you noted it doesn't handle multiple periods well (which are exceedingly common in emails - e.g. my.name@gmail.com).

iPhone access would be easier if people used the code blocks more effectively, I think, but maybe not. the forum web design is... I believe the correct word is "peculiar".
__________________
Philosophy is a battle against the bewitchment of our intelligence by means of language. -LW-
tw is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 11:18 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.