• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
A script for changing to next/prev mailbox in mail via short cut key
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

A script for changing to next/prev mailbox in mail via short cut key


  • Subject: A script for changing to next/prev mailbox in mail via short cut key
  • From: Tommy Bollman <email@hidden>
  • Date: Wed, 19 May 2010 01:38:07 +0200

Hello.
I have made an applescript for switching through the mailboxes in Mail.app, by the use of a single shortcut key.
ctl-j for next mailbox and ctl-k for previous mailbox. I call the two behaviours up and  down, which can be set by a variable so that you can have two instances of the script, one named up and one named down.
The script is supposed to select the first message, which can be really anything depending on how you have sorted that particular mailbox.

This "Highligting" doesn't always work. The problem is that some messages are threaded. In other scripts I have managed to get the class of the item of the messages of the selected mailboxes to return "Application".
Then I knew I'd hit the "heading" for a thread and could take action. If somebody could help me with with, so that 
messages always becomes hight lighted when I switch to the next mail box I'd be very happy.
The script works pretty good as it is. It is just the finish, I like stuff to work all of the time...

 
This scripts runs under SL, with Mail.app version 4.2
© Tommy Bollman Put in public domain, If change/fix this please post it back to the user-list
Please keep my name on it, and eventually state what changes you have made.
Enjoy! 
------
global mboxList, mboxCount, nwActiveMbox, fMsg, theCurrent, _DOWN, _UP, direction, visMsgs,  tcl, tstItm, tstClass
set mboxList to {}
set fMsg to {}
set visMsgs to {}
set nwActiveMbox to {}
set _DOWN to 1
set _UP to -1
set tcl to ""
set tstClass to ""
set tstItm to {}
-- set acctMboxCount to 0
set mboxCount to 0
copy _DOWN to direction
tell application "Mail"
activate
my makeMboxList()
set had to false
tell front message viewer
set selMboxCount to count of selected mailboxes
if selMboxCount > 0 then
set selMboxes to selected mailboxes as list
set had to true
end if
end tell
if had = false then
if direction = _DOWN then
set curpos to 1
else
set curpos to mboxCount
end if
copy (item curpos of mboxList) to nwActiveMbox
my updateMessageViewer(curpos)
else
if selMboxCount > 1 then
if direction = _DOWN then
copy contents of (item mboxCount of selMboxes) to theCurrent
else
copy contents of (item 1 of selMboxes) to theCurrent
end if
else -- selMboxCount = 1
set theCurrent to item 1 of selMboxes
end if
set curpos to my posInList(theCurrent, mboxList)
if direction = _DOWN then
if curpos = (count of mboxList) then
set curpos to 1
else
set curpos to curpos + 1
end if
else
if curpos = 1 then
set curpos to mboxCount
else
set curpos to curpos - 1
end if
end if
copy item curpos of my mboxList to my nwActiveMbox
end if
end tell
my updateMessageViewer(curpos)


on makeMboxList()
tell application "Mail"
set tmpList to every mailbox
repeat with aBox in tmpList
set end of my mboxList to contents of aBox
end repeat
set my mboxCount to count of my mboxList
end tell
end makeMboxList

on updateMessageViewer(msgBoxIndex)
local msgCount, sect
set sect to 1
tell application "Mail"
try
tell front message viewer
activate
set msgCount to count of messages of my nwActiveMbox
repeat until msgCount is not 0
if my direction is my _DOWN and msgBoxIndex is my mboxCount then
set msgBoxIndex to 1
else if my direction is my _UP and msgBoxIndex is 1 then
set msgBoxIndex to my mboxCount
else
set msgBoxIndex to msgBoxIndex + (my direction)
end if
copy item msgBoxIndex of my mboxList to my nwActiveMbox
set msgCount to (count of messages of my nwActiveMbox)
end repeat
set sect to 2
set selected mailboxes to {my nwActiveMbox}
set sect to 3
-- set my visMsgs to its visible messages
if my direction is my _DOWN then
-- THIS IS THE SPOT WHERE I'D LIKE TO GET "Application" returned in stead of 
                     -- "Message" when the Message is a header for a thread.
set my fMsg to last message of my nwActiveMbox
set my tstItm to item -1 of messages of my nwActiveMbox
set my tstClass to class of my tstItm
-- set my fMsg to {last item of my visMsgs}
else -- message istedet for item 
set my fMsg to first message of my nwActiveMbox
set my tstItm to item 1 of my nwActiveMbox
set my tstClass to class of my tstItm
--set my fMsg to {first item of my visMsgs}
end if
set my tcl to class of my fMsg as text
-- display dialog tcl
set sect to 4
if my fMsg is missing value or my fMsg is null then
tell me to display dialog "HOLA"
end if
set sect to 5
set its selected messages to {my fMsg}
end tell
on error e number n
display dialog e & " sect = " & sect
end try
end tell
end updateMessageViewer

on posInList(what, mylist)
local ctr
if (count of mylist) = 0 then
log "Empty list "
return 0
else
set ctr to 1
repeat with anItem in mylist
if contents of anItem is contents of what then
return ctr
else
set ctr to ctr + 1
end if
end repeat
return 0 -- NOT FOUND 
end if
end posInList


Regards


Tommy Bollman



--------------------

No act of kindness, no matter how small, is ever wasted.
-- Aesop

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Prev by Date: Selecting a folder from the sidebar in a save dialog
  • Next by Date: Re: Selecting a folder from the sidebar in a save dialog
  • Previous by thread: Re: Scripting InDesign CS3 print dialog box
  • Next by thread: User interface options besides AppleScript Studio?
  • Index(es):
    • Date
    • Thread