Posts Tagged “AppleScript”

After fixing the OS X Terminal’s keyboard shortcuts, I wanted to conquer the annoying functionality that keeps Terminal open after the last terminal tab is closed. I normally exit a shell by typing the command “exit”. However, you can also exit a shell by closing the Terminal tab using Cocoa methods (red close button, CMD+w). Between these two methods, things happen in a different order. (Using “exit” causes the user to logout and exit the shell, but the actual tab or window stays open until the processes end. On the other hand, using one of the window closing methods closes the window before the user logout and the processes end).

The general approach is to first watch for the EXIT signal to be sent to a shell (this happens regardless which way the Terminal is closed), then do some handling to determine if the user is exiting the last Terminal tab. However, this got rather cumbersome because of the behavior outlined above. (Sometimes when the final EXIT signal is caught there is still a tab open, other times there is no tab open when the final EXIT signal is caught). So anyway, this is how I did it.

Read the rest of this entry »

Tags: , , , , , , , , , ,

Comments No Comments »

I recently switched to the Mac for my work computer (with Windows XP in parallels… I have some VBA macros that are necessary to do my job. Over time, I expect to replace most of it with AppleScript.)

The other day, I noticed some weird emails in my Sent Items Folder in Entourage. They did not have a sender or a subject. If I opened them up, I could see all the headers and any html tags(if any). under the displayed headers, I could see that it was indeed emails that I was sending, but they were somehow becoming corrupted. Today, I figured out that they were emails being sent with my iPhone using my exchange account. I did a little searching and found out that there is a bug that adds some junk to the email header. Outlook on the PC doesn’t get the bad headers because of the way it connects to the server or it just ignores the bad header (it wouldn’t suprise me if the latter was the case).

Fortunately, it is just a simple added three lines at the top of the email and this should be correctable with a script. Since I am trying to learn AppleScript anyway, I thought I would take my chances. After reading a view discussions and blog posts on the issue with some suggested fixes and scripts, I came across an AppleScript made to correct the problem that I decided to examine. Unfortunately, this script didn’t work at all for me, but from looking at the script, it appeared this was mainly due to how it was attempting to detect the “bad email”. Pretty much every “solution” I found required the user to select one or more messages in Entourage and running a script from the Entourage Script menu. Not a very elegant solution, in my opinion. On top of that, it appears that Entourage does not allow AppleScripts to directly modify the email and save it back anyway. Well, I need better detection, and the ability to link the script to an Entourage Rule (and maybe still maintain the ability to run it from the script menu if I wanted.) So, I did and here you go:

Download:

FixSentFromiPhone_1.2.scpt.zip

Here is how I setup my Rule in Entourage to make it run automatically when new message arrive in my sent items folder:
Execute If all criteria are met
If
Folder Is Sent Items
Specific Header Subject Does not exist
Then
Run AppleScript FixSentFromiPhone.scpt

UPDATE: I found that there is a much easier way to do a portion of the script I wrote and updated it.

UPDATE2: It appears my script needs to be made more flexible in order to handle messages with multiple recipients (at least it didn’t work correctly when I did a “reply to all”). I am thinking about it and may update soon.

UPDATE3: Since I had not gotten around to it yet, a reader modified my script and sent me the changes he made to handle messages that had been sent to multiple destinations. I then took his changes and integrated them into the script. Everything seems to work well for me. The download above has been updated. Thanks!

Tags: , , , , , , ,

Comments 10 Comments »