Can an applescript be made to stop when in a repeat?
Hi all,
Im very new to applescript but have made what seems to be a functioning applescript to save attachments from emails based on some examples I found through internet searches. My current problem is that, once I have set it to run I cant quit it until it is finished. Is there some script I am missing to make it quit? I have tried:-
On quit
tell me to quit ---- or quit me -- or various combinations
end quit
I think the issue is that the quit command gets 'lost' as the script is 'trapped' in a repeat loop until it finishes the task. The only way I have found to stop it is through force quitting the application.
Below is my script for reference.
using terms from application "Mail"
on perform mail action with messages theMsges
set FolderChoose to choose folder with prompt "Choose the folder"
repeat with ThisMessage in theMsges
set nameof to "DONTGO" --- variable to stop creating folders if an attachment does not exist
tell application "Mail"
set Attached to mail attachments of ThisMessage
repeat with ThisAttach in Attached
set nameof to name of ThisAttach
end repeat
end tell
try
set nameof2 to nameof
on error
set nameof to "DONTGO"
end try
if not nameof is "DONTGO" then
set Mesdate to date received of ThisMessage
set {year:y, month:m, day:d} to Mesdate -- series of commands to get the date in the format I want to create the folder name
set y to y as string
set y to text 3 thru 4 of y
set m to m as integer
if d < 10 then set d to "0" & d as string
if m < 10 then set m to "0" & m as string
set filename to y & m & d as string
try
tell application "Finder"
make new folder at alias (FolderChoose as text) with properties {namefilename as text)}
end tell
end try
set newfolder to FolderChoose & filename & ":" as string
tell application "Mail"
set Attached to mail attachments of ThisMessage
repeat with ThisAttach in Attached
try
save ThisAttach in (newfolder as text) & (name of ThisAttach as text)
end try
end repeat
end tell
end if
end repeat
end perform mail action with messages
end using terms from
using terms from application "Mail"
on run
tell application "Mail" to set sel to selection
tell me to perform mail action with messages (sel)
end run
end using terms from
What you're asking is a little off the beaten track for applescript (applescript is not threaded, and is intended to run from beginning to end without interruption). If you think it's worth the effort, you can fake it. The easiest way I can think of, off hand, is to use a stay open application, and break up the code execution in the idle handler. the pseudocode for that would be something like:
global listIndex, globalList
on run
set listIndex to 1
tell application "Mail"
set globalList to messages
end tell
end run
on idle
repeat with idx from listIndex to listIndex + 50
tell application "Mail"
-- process item idx
end tell
end repeat
-- advance index to start of next 50
set listIndex to listIndex + 50
-- idle for a tenth of a second, to give the application the opportunity to process any pending quit request
return 0.1
end idle
it's not elegant, but it would work. There might be other ways to accomplish it, but I'd have to think on that a bit.
Similar Messages
-
How can I prevent the cursor from stopping when I press down on the trackpad?
On my MacbookPro 13" Retina with the new trackpad, when I press down on it and get the force feedback, the cursor stops moving even if I'm still moving my finger. This happens when I miss-click and try to correct myself and when I'm dragging something. It drives me nuts!
How can I disable it?Hi Esquared!
Thanks for your answer. The problem with this is the following: "Also note that this will only work for applications and text fields that are coded with Apple’s text view coding objects, so programs that use alternative text handling routines may not show a difference in blink rate." So it does only work for pages and keynote and textedit but not for the menu itself and the browser and alle the other areas.
It seems like there is no overall, no global command available..what a pity -
How can i fix the slowenss or stop when i open my mail at yahoo and hotmail?
when i open my yahoo and hotmail i feel that the pc stops for nearly a minute to continue loging and opening the e-mails.. and also i receive a message from other website to continue or stop script...
i face these two problems...'''@Waka_Flocka_Flame'''
Cleaning registries manually can cause damage to your computer, but cleaning registries using a registry cleaning program like [http://www.piriform.com/ccleaner CCleaner] is very important to your computer's health.
''Bad registries'' can prevent your computer from booting properly, so removing those registries in important. Bad registries can be caused by a number of things:
* Missing Shared DLLs
* Unused File Extensions
* ActiveX and Class Issues
* Type Libraries
* Applications
* Fonts
* Application Paths
* Help Files
* Installers
* Obsolete Software
* Start Menu Folders
* MUI Cache
* Sound Events
* Windows Services
* And More...
Personally, I run [http://www.piriform.com/ccleaner CCleaner] before a shutdown my computer.
I highly recommend scanning, to increase your computer's performance and to keep it fully functional.
'''NOTE: '''As with any software, use caution when using it and only download it from a trustworthy source. -
I have a new laptop with Windows 8 as operating system. Installed latest version of iTunes ontop computer. I can play music in My Library but when I click on iTunes, I get the message " iTunes has stopped working. A problem caused the program to stop working correctly. Windows will close the program and notify if a solution is available."
Anyone know what is the cause and if there is a resolution? Have tried to re-installing iTunes and have also tried restoring laptop to an earlier date.iPad not appearing in iTunes
http://www.apple.com/support/ipad/assistant/itunes/
iOS: Device not recognized in iTunes for Mac OS X
http://support.apple.com/kb/TS1591
iOS: Device not recognized in iTunes for Windows
http://support.apple.com/kb/TS1538
iTunes for Windows: Device Sync Tests
http://support.apple.com/kb/HT4235
IOS: Syncing with iTunes
http://support.apple.com/kb/HT1386
Apple - Support - iPad - Syncing
http://www.apple.com/support/ipad/syncing/
iTunes 10.5 and later: Troubleshooting iTunes Wi-Fi Syncing
http://support.apple.com/kb/ts4062
The Complete Guide to Using the iTunes Store
http://www.ilounge.com/index.php/articles/comments/the-complete-guide-to-using-t he-itunes-store/
iTunes Store: Associating a device or computer to your Apple ID
http://support.apple.com/kb/ht4627
Can't connect to the iTunes Store
http://support.apple.com/kb/TS1368
iTunes: Advanced iTunes Store troubleshooting
http://support.apple.com/kb/TS3297
Best Fixes for ‘Cannot Connect to iTunes Store’ Errors
http://ipadinsight.com/ipad-tips-tricks/best-fixes-for-cannot-connect-to-itunes- store-errors/
Try this first - Reset the iPad by holding down on the sleep and home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider - let go of the buttons.
This works for some users. Not sure why.
Go to Settings>General>Date and Time> Set Automatically>Off. Set the date ahead by about a year.Then see if you can connect to the store.
Cheers, Tom -
I can listen to the Music Library in my Ipad through home sharing, but I can't do it in my Iphone. When Iphone managed to connect my Mac, I can see how a watch turns clockwise but it stops when it arrives at a half of the watch. What can I do?
Hi there,
You may want to take a look at some of the troubleshooting steps found in the article below.
Troubleshooting Home Sharing
http://support.apple.com/kb/ts2972
Hope that helps,
Griff W. -
Hi, I upgraded my girlfriend's iPad 2 using my iMac, however, her iPad was sync with her PC. Although I've made backup earlier, when I restore from backup the apps doesn't sync back, neither her documents on pages. How can I put then back to her iPad?
The backup saves many settings, but it copies photos and other files from the computer back to the iPad after IOS5 wipes the disk. Plugging it into her computer will re-sync it.
-
I am creating an automotive braking system using flash and have a wheel turning. I want the wheel to slow down and stop after the brake pedal is pushed at a certain frame. I know I could do this with frame by frame animation but was hoping there was a short cut - javascript?? If not the slowing down portion then is there code for just making the internal movie clip (wheel turning) to stop when it gets to a frame.? Thanks
you can use the ticker class to create a loop that you use to control the wheel's rotation or frame, TweenJS v0.6.0 API Documentation : Ticker
-
Hello! I was on my Mac and then I clicked on iTunes. Then I clicked on Account, and accidentally removed my device from my Mac, how can I get it back? Also when I plug my iPod into the computer, it downloads everything that is on my computer, how can I stop this. please help! please help!!!!!!thank you
Is the iPod still singed into the account isn Settings>iTunes and App Stores and SettingsZ>iCloudl? If it is then I would not be concerned.
Also see:
iTunes Store: Associating a device or computer to your Apple ID
since you may have started the 90 day window.
For the other "problem", go to iTunes>Preferences>Devices and check the box that says Prevent iPod....automatically syncing. -
The Question says it all really.
Is there any way i can log onto Game Center via just my Username as i have forgotten the other details (I made the account when i was 11 - I'm now 14 and have a bad memory)?
I remember my Username on Gamcenter but due to the recent update of iOS7, it is only letting me Sign in through my APPLE ID - which i have forgotten over time. I wish to recover my account recently because I remember purchasing Gems on the game 'Clash of Clans' and I wish I could restart playing the game.
Many thanks for taking your time to read and answer this question.
-Gavin Chong.Hey xChongy!
I have an article here that can help you find that forgotten Apple ID:
Apple ID: How to find your Apple ID
http://support.apple.com/kb/HT5625
Thanks for using the Apple Support Communities. Have a good one!
-Braden -
started to run recovery disc assistant on a backup hard drve-stopped when it said it would erase all data-but now can't inialize the external drive nor repair it with disc utility. what to do?
Activity Monitor – Monitor Performance Problems
Performance Guide
Why is my computer slow
Why your Mac runs slower than it should
Slow Mac After Mavericks
Things you can do to resolve slowdowns see post by Kappy
Try running this program and then copy and paste the output in a reply. The program was created by Etresoft, a frequent contributor. Please use copy and paste as screen shots can be hard to read.
Etrecheck – System Information -
Recharging my iPod shuffle (3rd gen.) on my 2009 iMac (OS 10.5.8) goes extremely slowly (via usb port at the back). This is mainly because recharging stops when my mac goes to sleep. I just can't believe that Apple doesn't have a sollution for this, but I haven't found it yet... What's the most efficient way of recharging?
Purchase a wall charger for it instead.
B-rock -
Can anyone help with issue whereby Music, Podcasts and Audiable Book Apps keep stopping when listing via Headphones following IOS 7.06 Updates on Iphone 4?
I have tried the following all ready:
Resetting Phone
Resetting Settings on phone
Change Headsets to speakers
Reinstalled Phone
Updated to IOS 7.1
No of the above has resolved the issue does anyone have any ideas?Can anyone help with issue whereby Music, Podcasts and Audiable Book Apps keep stopping when listing via Headphones following IOS 7.06 Updates on Iphone 4?
I have tried the following all ready:
Resetting Phone
Resetting Settings on phone
Change Headsets to speakers
Reinstalled Phone
Updated to IOS 7.1
No of the above has resolved the issue does anyone have any ideas? -
Hi
I have a Iphone4 in using. I couldn't find Safary, E-mail and notes from my phone one day. I made this mistake when I want to delete some programe from my phone. Who can help I recovery my phone please.
ThanksHello, HenryWang2103.
Thank you for visiting Apple Support Communities.
The Safari, Email and Notes applications are native to the iOS and is unable to be deleted. Since this is the case, they are either in a folder on the iPhone, on another page or Restrictions are enabled. You can also search for these Apps on the iPhone by touching the screen and sliding your finger down. Here is some information regarding these features. The information about folders is located in the user guide below.
iPhone User Guide
iOS: Understanding Restrictions (Parental Controls)
http://support.apple.com/kb/HT4213
Cheers,
Jason H. -
how can i say yes to automatic updates when they stop my wireless dlink to Virgin home broadband from getting on the internet and then i have to do a system restore to the day before the update to get it back to normal?!? Frustrated
== This happened ==
Not sure how often
== automatic updates go on my computer, say if i click yes to update when shutting downYou have 10.6 on that machine, I suggest you stick with it for performance, third party hardware and software reasons as long as possible.
Consider 10.8 (not 10.7) when it's released, because 10.7 and 10.8 will require a new investment in software and newer third party hardware as it requires newer drivers the old machines won't have. (forced upgrade because of software, really nice of them)
http://roaringapps.com/apps:table
Far as your Safari problem do these things until it's resolved:
1: Software Update fully under the Apple menu.
2: Check the status of your plug-ins and update (works for all browsers) also install Firefox and see if your problems continue. You should always have at least two browsers on the machine just in case one fails.
https://www.mozilla.org/en-US/plugincheck/
Flash install instructions/problem resolution here if you need it.
How to install Flash, fix problems
3: Install Safari again from Apple's web site
https://www.apple.com/safari/
4: Run through this list of fixes, stopping with #16 and report back before doing #17
Step by Step to fix your Mac -
Can iTunes be set to play only one song and then stop when the song is finished and not go on to play another unless commanded?
If you uncheck all of the songs, they will only play if explicitly commanded. Command-click in a checkbox and they will all be unchecked. Command-clicking again will check the all again should you want to do that.
Maybe you are looking for
-
Time Machine Utterly Failed?
I have been regularly backing up my MBP since I bought it and lately I've been having major troubles with it. I wanted to restore to a few weeks ago but when I got to that spot in Time Machine all I see are the files that were on my desktop. I can't
-
Verizon Access Manager 7.0.8 and 10.6.3 results in fatal error -43
I am trying to get a Verizon modem (UW190) working with my Macbook Pro and 10.6.3. Using 7.0.8 of VZAccess Manager. The modem is detected properly but when you try to activate vzaccess will immediately return a fatal error -43. If you try to connect
-
I have an ISE 1.2 I am configuring it with Machine authentication with PEAP , Users are working Fine Just he connect his Cable , it authenticate his Machine and Machine dACL is Downloaded then he log in with his username/password and NAC starts pr
-
How to bring a custom data element into another ods object
I have an ods object which has a custom data element called customer purchase order number. I have another ods object which needs that custom data element. Both these ods objects are part of a multiprovider. How do I make the customer purchase order
-
I set up Firefox sync today with Firefox 4.0b7 (Firefox 4 Beta 7) and my ipod touch (Firefox Home app). I got it to sync and it synced almost everything except for my history. It did sync 2000 pages of my history but I checked and I have way more tha