Total n00b here, definitely not a programmer. Would love some assistance with an applescript. I'm basically trying to extract a subject line from emails in a particular folder underneath my inbox. I need it to yank out the subject line, look for some numbers (ex. 123456) and pull out the last 4 digits. Then put that into a text file. Below is what I have so far, but it's not working. I'm not getting any output at all. Any guidance would be greatly appreciated!
tell application "Microsoft Outlook"
set theAccount to exchange account “my account"
set topFolder to folder "Inbox"
set subFolder to folder “Stuff"
set theMessages to messages of subFolder
set folderPath to ((path to home folder from user domain as string) & “emails")
repeat with aMessage in theMessages
my SetSubject(subject of aMessage)
end repeat
end tell
on SetSubject(theSubject)
tell application "Microsoft Outlook"
try
save theSubject in ((path to home folder from user domain as string) & “emails" & “numbers.txt" as string)
end try
end tell
end SetSubject
end
I don't know what your criteria are to filter the subjects.
This is an example to write the last 4 characters of all subjects of the messages in the specified mailbox into a file numbers.txt in folder emails in the home folder, one subject per line.
If an error occurs – for example the number of characters in the subject is less than 4 – the file is closed reliably and the script aborts.
set numbersFile to (path to home folder as text) & "emails:numbers.txt"
tell application "Microsoft Outlook"
set theSubjects to subject of messages of folder "Stuff" of folder "Inbox" of exchange account "my account"
end tell
try
set fileDescriptor to open for access file numbersFile with write permission
repeat with aSubject in theSubjects
write (text -4 thru -1 of aSubject & return) to fileDescriptor starting at eof
end repeat
close access fileDescriptor
on error
try
close access file numbersFile
end try
end try
Related
I have a script that I'm using to automate a small workflow but I am stuck trying to get the Subject to list the current month.
Here is my script:
tell application "Finder" to set selectedItem to item 1 of (get selection)
set theAttachment to selectedItem as alias
set fileName to name of selectedItem
tell application "Microsoft Outlook"
set newMessage to make new outgoing message with properties {subject:"(current month) as string Message from John Doe"}
tell newMessage
make new attachment with properties {file:theAttachment}
end tell
open newMessage
get newMessage
end tell
Is this possible? I've tried searching online and in Script Debugger but I keep coming up short. Thanks in advance.
I don't use Microsoft Outlook, so I'm going to assume that your script executes without error, but simply produces an undesired result, namely an new outgoing email with the words "(current month) as string Message from John Doe" in the subject line.
On this basis, to get your subject line to contain only the current month, find the relevant line in your script that contains this:
{subject:"(current month) as string Message from John Doe"}
and replace it with this
{subject:(current date)'s month as text}
If you want the subject line to include additional text after the month, as your original script does, then you can instead replace it with this:
{subject:((current date)'s month as text) & " Message from John Doe"}
I'm trying to get the bibliographic information of the currently open PDF in Skim.
To do that, I am comparing the file to the linked files of all the publications I have in BibDesk.
But for some reason, that comparison doesn't work:
tell application "Skim"
set theFile to the file of the front document
tell application "BibDesk"
repeat with currentPub in publications of front document
set bibFile to linked file of currentPub
if bibFile = theFile then
say "lala"
end if
end repeat
end tell
end tell
The script does get both theFile and bibFile correctly, but comparing them doesn't work. Why is that and what do I need to do differently?
Turns out it's super easy: you just have to compare with as string:
tell application "Skim"
set theFile to the file of the front document
tell application "BibDesk"
repeat with currentPub in publications of front document
set bibFile to linked file of currentPub
if bibFile as string = theFile as string then
say "lala"
end if
end repeat
end tell
end tell
I am trying to send attachments via Mail App and have a list of file names without extension in the source text file. Each line will be looped until all lines in the text file finished.
How do I make a path for the attachment using looped lines of the source text and add the extension to the end?
This is what I use to read the lines from the text file and loop them
set lns to paragraphs of (read file srcFile as «class utf8»)
repeat with ln in lns
This is what the send attachment part of the script look
set theAttachmentFile to "Macintosh HD:Users:attachmentfolder" + ln + ".pdf"
The above is not working.
Thanks!
If your text file contains only file name without path and extension, I assume that the folder path where these files are stored is known before in the script: correct ?
About extension, it is much easier to store it also in the text file for 2 reasons : if you don't, you need to get every file whose name contains "xxx", and cross your fingers that you find one an only one file. if there are 2 files with same title but different extension...you can't select !
The script for creating new email and add attachment should be :
Tell Application "Mail"
Set newMessage to make new outgoing message with properties {visible:true, subject:My_Subject, content:My_Content}
tell newMessage
make new to recipient at end of to recipients with properties {name:"", address:send_to_addr}
make new attachment with properties {file name:TheAttachmentFile} at after the last paragraph
end tell
end tell
So I have an Applescript to help with naming photo's appropriately for data entry to assign it to a Unique ID. Since we're using Mac's this is done in AppleScript. This works great but it's only for one machine. What is now needed is to work on multiple machines. What I want to do is put the photos on our server and have the client machines do the action on the folder from there.
The problem I am currently having is that the script does not authenticate the user and does not run the script even though the info is correct. Am I doing this correctly?
tell application "Finder" of machine "eppc://user:password#server.local"
set renameFiles to the selection
set inventoryFiles to every file in folder (((path to documents folder) as text) & "Inventory Photos")
set currentIndex to the count of inventoryFiles
repeat with i from 1 to the count of renameFiles
set currentFile to (item i of renameFiles)
set new_name to ((10000 + currentIndex + i) as text) & ".jpg"
set name of currentFile to "a" & new_name
end repeat
end tell
Thank you for any help
I am trying to write a script that does the following job: it goes through all of the emails in the mailbox, finds the ones that have the word "French" in their subject line and then copies all the subject lines of those emails in a text file. Here is what I came up with
tell application "TextEdit"
make new document
end tell
tell application "Mail"
tell the mailbox "Inbox" of account "tigeresque#gmail.com"
set numm to count of messages
repeat with kk from 1 to numm
set wordsub to subject of the message kk
tell application "TextEdit"
if "French" is in wordsub then
set paragraph kk of front document to wordsub & return
end if
end tell
end repeat
end tell
end tell
Unfortunately, I keep receiving the error
"TextEdit got an error: The index of the event is too large to be valid."
and I have already spent a couple of hours trying to fix it without much success. Could you please take a look at my code and see what is wrong with it?
Your main problem is that the number of paragraphs in TextEdit and the number of email messages have nothing to do with each other, so if you're counting on the number of messages then TextEdit will not understand it. For example you may have 50 messages but TextEdit does not have 50 paragraphs so it errors. As such we just use a separate counter for TextEdit.
I made other changes too. I often see errors happen by having one "tell application" block of code inside another... so I separated them. Also notice that the only code inside of any "tell application" block is only what is necessary for that application to handle. This too avoids errors. These are good habits to have when programming.
Therefore give this a try...
set searchWord to "French"
set emailAddress to "tigeresque#gmail.com"
tell application "Mail"
set theSubjects to subject of messages of mailbox "INBOX" of account emailAddress
end tell
set paraCounter to 1
repeat with i from 1 to count of theSubjects
set thisSubject to item i of theSubjects
if thisSubject contains searchWord then
tell application "TextEdit"
set paragraph paraCounter of front document to thisSubject & return
end tell
set paraCounter to paraCounter + 1
end if
end repeat