Controlling and directing a repeat loop

I thought I was getting the hang of applescript, but have been working on this one for a few days to no avail...must be an easy solution and I just don't see it. Anyway... I have a set of data in Excel that I have successfully read into a list and am trying to use the data to control the way it is put into another Excel file, specifically a number of different sheets within a series of Excel files. I'll post the entire script I have at the bottom of this post, but essentially here is the issue: If a list has something like {{2010,B,T001,201},{2020,C,T001,202},{2020,C,T002,301}} how might I use the fact that the third item in the list of lists (think I am saying that correctly) changes to control where the script puts the data. In other words I want the last set of data {2020,C,T002,301} to go to another Excel sheet based on the fact that it has a different value in the third item as compared to the earlier sets of data...hope I haven;t confused you! Here is the script that I "working" right now.
Thanks,
dan
<pre style="
font-family: Monaco, 'Courier New', Courier, monospace;
font-size: 10px;
margin: 0px;
padding: 5px;
border: 1px solid #000000;
width: 720px; height: 340px;
color: #000000;
background-color: #FFDDFF;
overflow: auto;"
title="this text can be pasted into the Script Editor">
-- Works with an Excel file [csv is ok] to move scheduled sections from one Excel file into another Excel file set up as a daily Schedule  for the courses taught by a teacher.  Each daily schedule file will be dept based and have multiple workbooks--
tell application "Microsoft Excel"
activate
open file "MacBook HD:Users:Dano:School:Scheduling:Applescript & Excel Files:09-10 Teacherdata.xlsx"
activate object workbook "09-10 Teacherdata.xlsx"
activate object worksheet "Sheet 1"
get value of used range of worksheet 1 of file "MacBook HD:Users:Dano:Desktop:09-10 Teacherdata.xlsx"
copy the result to wholedata
set lvalue to length of wholedata
set counter to lvalue
set cellnum to 1
set cellid to ""
set slotvalue to ""
set deptname to {"English", "Humanities", "Mathematics", "Language", "Science", "Arts"}
set deptnamefile to {"MacBook HD:Users:Dano:School:Scheduling:Applescript & Excel Files:English Schedules 10-11.xlsx", "MacBook HD:Users:Dano:School:Scheduling:Applescript & Excel Files:Humanities Schedules 10-11.xlsx", "MacBook HD:Users:Dano:School:Scheduling:Applescript & Excel Files:Mathematics Schedules 10-11.xlsx", "MacBook HD:Users:Dano:School:Scheduling:Applescript & Excel Files:Language Schedules 10-11.xlsx", "MacBook HD:Users:Dano:School:Scheduling:Applescript & Excel Files:Science Schedules 10-11.xlsx", "MacBook HD:Users:Dano:School:Scheduling:Applescript & Excel Files:Arts Schedules 10-11.xlsx"}
set columnchoices to {"J", "K", "L", "M", "N", "O", "P", "Q"}
set teachingslot to {"A ", "B ", "C ", "D ", "E ", "F ", "G ", "H "}
set cvalue to {0, 0, 0, 0, 0}
set tid to ""
repeat with i from 2 to counter
copy item i of wholedata to cvalue
copy item 3 of cvalue to tid
repeat with i from 1 to 6
if item 5 of cvalue = item i of deptname then
if item 3 of cvalue = tid then
tell application "Microsoft Excel"
activate
open item i of deptnamefile as alias
activate object worksheet 1
set nextfile to item i of deptnamefile
end tell
copy item 2 of cvalue to slotvalue
repeat with i from 1 to 8
if slotvalue = item i of teachingslot then
if tid = item 3 of cvalue then
set cellid to item i of columnchoices & "3"
set formula of cell cellid to item i of teachingslot
set formula of cell "J1" to item 3 of cvalue
save
else
activate object worksheet 2
set cellid to item i of columnchoices & "3"
set formula of cell cellid to item i of teachingslot
set formula of cell "J1" to item 3 of cvalue
save
end if
end if
end repeat
tell application "Microsoft Excel"
close workbook 1 saving yes
end tell
end if
end if
end repeat
end repeat
set onepiece to {}
set lastrow to {}
set courseID to {}
end tell </pre>

ok...thanks to the last 2 posters for the help. I think this is moving me in the right direction, but have a few questions/points:
You're welcome Dan! Let me see if I can help some more...
when I use ...repeat with aList in theList is "aList" a variable that I have to define or does it pull off the a list at a time from a list of lists (that's what I'd like it to do).
aList is a variable that contains a list. It is what you're wanting it to be.
Not sure I understand the command... log "made new spreadsheet " & lastThirdItem what is this log command? (guess I'll look into this, although it isn't in my Applescript book (Applescript 1-2-3))
The log command is useful to "log" information in your script as it goes along. It's primary use is for debugging a script. If you click on "Events" (located at the bottom of the ScriptEditor window, just to the left of "Replies" and "Result"), you can watch for useful information about the progress of your script as it executes. The log command can be safely omitted.
Point of clarification: my list that includes {"20501", "B", "T1441", "201", "Humanities"} is large... 280 rows of data, and it changes from year to year. Since it is in Excel I can sort it and group the data based on the 3rd item ("T1441"), but the number of times this variable shows up...varies and thus I guess I'm looking for a way to load the data into a list and then have Applescript work through it parsing the data that has the same 3rd item into one worksheet, and then the next group of data that has the same 3rd item into another worksheet and so on, with the 4th item controlling the workbook it is going to. I think I might just start from scratch after looking into these alist and log commands.
If I'm understanding you correctly, the following script example should get you started in the right direction to achieve what you are looking to do...
<pre style="width:630px;height:auto;overflow-x:auto;overflow-y:hidden;"
title="Copy this code and paste it into your Script Editor application.">set theLists to {{"20501", "B", "T1441", "201", "Humanities"}, {"10601", "A", "T1561", "102", "English"}, {"20502", "D", "T1441", "201", "Humanities"}, {"20503", "F", "T1441", "201", "Humanities"}, {"36251", "E", "T1661", "103", "History"}, {"20504", "H", "T1441", "201", "Humanities"}, {"10101", "J", "T1661", "103", "History"}}
set thirdItemList to {}
repeat with aList in theLists
set thisThirdItem to item 3 of aList
if thisThirdItem is not in thirdItemList then copy thisThirdItem to end of thirdItemList
end repeat
repeat with thisThirdItem in thirdItemList
set thisItem to thisThirdItem as string
--make new spreadsheet
log "made new spreadsheet " & thisThirdItem
repeat with aList in theLists
if (item 3 of aList) as string is thisItem then
--do stuff to spreadsheet
log "adding info to spread sheet " & thisThirdItem
end if
end repeat
end repeat</pre>
The above script finds each different third item and makes a list of those. It then creates and appends information to one spreadsheet at a time until all third items have been accounted for. Harder to explain than to show someone in person! Run the above script in the ScriptEditor application and watch the "Events" log.
thanks,
dan
Again, you are welcome. I wish you luck my friend! Hope this helps some more...

Similar Messages

  • Interrupt repeat loops with buttons

    Hi,
    How do I make buttons available to the user while I run a repeat loop?
    I'm doing a shell script in the background and I'm using a repeat loop to read out the log of the results. Meanwhile, I want to have a Cancel button available to the user.
    The button however doesn't respond while the repeat loop runs, while the rest of my UI is in fact updating (based on the incoming log). I'm even using a one second delay at the beginning of the loop.
    I'm using AppleScript Studio in Xcode/Interface Builder.
    Thanks,
    JW

    1. Create a control in the window which has some sort of boolean property (if you are using a progress bar, then you already have one, since a progress bar can be indeterminate, and you can check this).
    2. Set the handler which shows the window (or alters the window when the process begins) to set this boolean property to a particular value
    3. Have the "Cancel" button handler invert the property
    4. Have the repeat loop check the property as part of its boolean condition (as in "repeat while x is true")
    Note that if the window is going to go away anyway when the process is complete, then you can use the window's title to indicate the status: set the title to "Cancelling..." and have the repeat loop check whether the title of the window is "Cancelling...".
    You could also just create a global within the script file, and have the repeat loop check the status of the global, but that tends to lead, sooner or later, to overlapping reuse of a single global value, which is a bug.

  • How to use Fuzzy Logic Controller for transfer function in labview control and simulation loop?

    I am facing problem with fuzzy PD logic controller for transfer function in control and simulation loop.
    Plz Help me in this regard...................
    i have attache snapshot of my program
    Attachments:
    fuzzy in simulation loop.JPG ‏52 KB

    Hi Sankhadip,
    Sorry for the late response. I was looking at your code and
    I noticed that the graph scale does not start from zero. That might be the
    reason why you don't see the transient in the simulation. To change the scales
    simply double click on the lower limit and set it to zero. If this is not the
    expected results, can you please post the expected results, so we can see what are the
    differences between the results . Also, you might be using different
    solvers, and that gives different results as well.    
    Thanks and have a great day.
    Esmail Hamdan | Applications Engineering | National
    Instruments

  • Repeat Loop times out and I don't want it to

    Maybe there is a better way to do this but I want an action to take place whenever the modification date of a certain file changes. This is what I use but it errors because of a timeout after about 10 mins if the mod date doesn't change. I need this to be checking all the time.
    on idle
    tell application "Finder"
    set UpdatedOLD to modification date of file aFile
    set UpdatedNEW to modification date of file aFile
    end tell
    repeat while UpdatedOLD = UpdatedNEW
    tell application "Finder"
    set UpdatedNEW to modification date of file aFile
    end tell
    end repeat
    end idle
    How can I get this to work?

    Hello
    I think you have stepped on a land mine set by OSX 10.6.
    There's a fatal bug in Apple Event Manager in 10.6 such that one event in every 65535 events will be lost and never be replied, which will result in Apple Event timeout error on sender. This bug has been reported shortly after the 10.6 release and has not yet been fixed as of 10.6.2.
    In your current script, you're continuously sending event to Finder and sooner on later send an event with the specific event id that is doomed to be lost. Judging from the time till you see the time out error, that is 10 min, you're at most sending 65535 / 600 = 109.225 events / sec to Finder. You can reduce the number of events by inserting some delay, e.g. 'delay 1' in your repeat loop but it can only defer the failure.
    cf.
    Re: Timed Out (Silence)
    http://lists.apple.com/archives/applescript-users/2009/Oct/msg00117.html
    Re: spurious timeout on nth Apple event on Snow Leopard
    http://lists.apple.com/archives/applescript-users/2009/Nov/msg00041.html
    A better way to achieve your task would be to let a launchd agent watch the file.
    A recipe is as follows.
    1) Save a compiled script in :
    ~/Library/Scripts/launchd/watchdog.1.scpt
    with contents :
    --SCRIPT
    -- Here put your script that is to be triggered when the file is modified.
    -- e.g.
    tell application "System Events"
    display dialog "The file is modified." giving up after 10
    end tell
    --END OF SCRIPT
    2) Save a UTF-8 plain text file in :
    ~/Library/LaunchAgents/watchdog.1.plist
    with contents :
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
    <key>Label</key>
    <string>watchdog.1</string>
    <key>Disabled</key>
    <false/>
    <key>Program</key>
    <string>/usr/bin/osascript</string>
    <key>ProgramArguments</key>
    <array>
    <string>osascript</string>
    <string>/Users/USER_NAME/Library/Scripts/launchd/watchdog.1.scpt</string>
    </array>
    <key>WatchPaths</key>
    <array>
    <string>POSIX_PATH_TO_THE_FIILE</string>
    </array>
    </dict>
    </plist>
    *Change USER_NAME to your user name and POSIX_PATH_TO_THE_FIILE to the POSIX path to the file to be watched.
    3) Issue the following command in Terminal to load the launchd agent :
    launchctl load ~/Library/LaunchAgents/watchdog.1.plist
    Or
    3a) Log-out and re-log-in to load the launchd agent.
    *The name 'watchdog.1.plist' and 'watchdog.1.scpt' and the script's location '~/Library/Scripts/launchd/' are mere examples. You may change them as you see fit.
    cf.
    http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/m an5/launchd.plist.5.html
    http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/m an1/launchctl.1.html
    Good luck,
    H
    Message was edited by: Hiroto (fixed typo)

  • How to structure a control and its display in the same while loop and same display panel (instead of display panel and a seperate parameter-setting panel )

    As you can see, I need to adjust the Target position to certain value (like 1068.88), the actual position is showing 1066.99.  What kind of flow control structure will achive this goal?
    Notice the Labview example "Vibration analysis"  may shed some light on this issue.  Will someone give out a simpler code to show how it works?
    Attachments:
    Spectrometer Control V3.0.vi ‏113 KB

    lightblue,
    Just to make sure we are on the same page, you would like to set the position, then monitor it.  Is that correct?  In that case, you might have a few options.  You could have a sequence that would set the position, and then a while loop that would monitor the position, however this wouldn't allow you to update anything else.  The other option would be to use parallel while loops, which would be similar to the parallel sequence structure you have below.  The only issue with this would be that if you are calling the driver from both loops, you could run into errors.  The Vibration Analysis.vi takes the setpoint, then calculates the actual available position, so it won't serve as a very good example, code-wise. 
    Hope this helps!
    Andy F.
    National Instruments

  • Table controls and step loops

    what are the differances between table controls and step loops?

    Hi
    It's only graphic diff. managed by diff. ways (of course):
    in steploop there isn't a table control so in PBO and PAI it has only the stataments LOOP/ENDLOOP or LOOP AT ITAB/ENDLOOP.
    The step loop is way older than table control to display the data of a table.
    check this
    Re: step loops, table controls
    -charitha.

  • I just installed an update on my iPhone and since then the choice to repeat music, or not, has disappeared and it automatically plays songs and albums on a loop. Anyone know how to make it play an album or song just once?

    I just installed an update on my iPhone and since then the choice to repeat music, or not, has disappeared and it automatically plays songs and albums on a loop. Anyone know how to make it play an album or song just once?

    Basics from the manual are restrt, reset, restore.
    Have you tried each of these?

  • Repeat loops and goto's

    Can I ask two questions please,
    Q1.
    is there a way of telling a repeat loop to 'step' over
    numbers, I cannot find anything in the help files that mention this
    at all....
    For example, repeat with i := 1 to 200 'step 2' This would
    result in values of 1, 3, 5, 7, etc etc
    For example, repeat with i := 1 to 200 'step 3' This would
    result in values of 1, 4, 7, 10, etc etc
    Q2.
    Goto commands in a calculation icon.
    I can only find a reference that will use the
    goto(IconID@"TARGETICON") Is there anyway I can use the goto
    command inside a calculation. I need to set up a logical test,
    basically to say that if this isn't true go back to here and do it
    again(a repeat loop won't work)
    One day I think I may just get the hang of
    this.........

    I didn't examine your code closely, but for the future, if
    you need to
    randomly pull values from a list and you don't want
    duplicates...
    Copy the list to a new list, then after you pull a value from
    the list
    within the loop, immediately use DeleteAtIndex to remove that
    value from
    the temporary list. So during the next iteration of the loop,
    the
    previously pulled value is not present to be pulled again.
    Erik
    The Pc Doctor wrote:
    > Many thanks for your suggestions, I think I just got
    caught up the my knowledge
    > of VB and the for next loop, the solution was so obvious
    now you mention it.
    >
    > The second one I've also solved by way of different
    Calculation icons. Here
    > is what I was doing (Please forgive the awful code, I am
    still new at this)
    >
    > The whole point of this is to select a chosen number of
    Questions from a list
    > of a certain amount of questions - the numbers are not
    known and is subject to
    > change.
    >
    > I would seed a random numbers (between 1 and QNo) into a
    list of up to Q0
    > numbers and then use the below code to check to any
    duplicate numbers. The
    > problem I had was finding a way of if I found duplicate
    numbers replacing them
    > and testing them again, and again until no duplicates
    exist.
    >
    > I put the below in it's own calculation icon called
    'CheckIt'
    > - - - - - -
    > SortByValue(QuestionStore, TRUE)
    > again := 0
    > repeat with i := 1 to Q0 - 1
    > if QuestionStore = QuestionStore then
    > QuestionStore := Random(1,QNo,1)
    > again := 1
    > end if
    > end repeat
    > - - - - - - - -
    > I then put the following in a following calculation Icon
    > - - - - - - - -
    > -- Test to see if we have duplicate numbers, if yes then
    go back to the check
    > random numbers Icon.
    > if again = 1 then
    > GoTo(IconID@"CheckIt")
    > end if
    > - - - - - - - - - -
    >
    > Well it works
    >
    > Thanks again
    >
    > Paul
    >
    Erik Lord
    http://www.capemedia.net
    Adobe Community Expert - Authorware
    http://www.macromedia.com/support/forums/team_macromedia/
    http://www.awaretips.net -
    samples, tips, products, faqs, and links!
    *Search the A'ware newsgroup archives*
    http://groups.google.com/groups?q=macromedia.authorware

  • Synchronize Control and Simulation loops

    When simulating control systems with LV Control and Simulation loops, I often have multiple loops running at different rates. For example, I have a PWM loop running at 20 kHz, a data acquisition loop running at 100 kHz, and a control loop running at 10 kHz. How can I synchronize all of these loops so that they stay on the same time base? Obviously the master time base will need to be at least as fast as the fastest simulation loop.
    I've tried synchronizing all loops to the 1 kHz clock (I'm running on Windows), but each loop runs one period per clock tick (e.g. my 20 kHz loop counts up 50us per clock tick, my 100 kHz loop counts up 10us per clock tick, etc). I need all of the loops to be synchronized to one master time base so the simulation time is identical in each loop, but each loop will be executed at a different rate.
    Any thoughts?
    Solved!
    Go to Solution.

    Hello,
    A quick suggestion - why can't you run all three systems in a single simulation loop, but have different sample rates for the blocks for each system ?
    Is your system entirely digital, or a mixture of continuous and digital - it may simplify things if you can convert everything to discrete time.
    Hope this helps,
    Andy Clegg
    Consultant Control Engineer
    www-isc-ltd.com

  • Could somebody teach me how to set the lastest iTunes so that it repeats just one of the numbers installed from the CD? I've alreadly tried it by clicking "control" and the bottom, but it doesn't work. Thank you.

    Could somebody teach me how to set the latest iTunes so that it repeats just one of the numbers installed from the CD?
    I've already given it a try by clicking "control" and the bottom item which means one item in Japanese, but it doesn't work.
    Thank you.

    You can access the repeat options if you right-click on the shuffle icon or if menus are enabled you can use
    Controls > Repeat > Off | All | One.
    Once the control is visible you can click it to switch between states as before. If the control is turned to off it disappears on the next track change. In contrast the shuffle control remains visible whenever it is appropriate. Hopefully the next release will fix this.
    The bottom one should do it.
    tt2

  • Resetting Integrator in Control and Simulation Loop

    Hello,
    I am trying to run a real-time simulation in Labview 14. I have prepared front panel controls and data flow such that I can reset the simulation to some preset initialization values upon clicking a button. However, I am not able to figure out how to reset the integrator in the control and simulation loop. Even after reinitialization of all the values, the integrators will overwrite the initialization values with whatever they were holding. Please help me find a way out.
    Thanks

    Please share what code you have so that we can see what you've tried and understand exactly what you're trying to do.

  • MSI Prime 8.1 tablet show logo and fireworks, then repeatedly reboots in a loop.

    MSI Prime 8.1 tablet show a logo and fireworks, then repeatedly reboots in a loop.  Any way to fix this or reset it?
    Thank you

    Update the FW by following the instruction and see if this can help.
    Download link:
    http://download.msi.com/archive/frm_exe/N821_v4.5rc5_v4.4_20140414.zip
    Update Guide:
    http://www.msi.com/files/pdf/Primo73_75_81_91_93firmware_recovery_en_21.pdf

  • Write a Labview program to control both speed and direction of stepper motors

    Hello,
    I am currently undertaking a project in University. As part of it I have to run two stepper motors at varying speeds, and one of them in forward/reverse. The motor I have for the project is a RS 191-8334 (V9728) and the controller is a RS 240-7920 (v10900). I have no experience of using Labview, and the version I have on my laptop is Labview 10. Any help would be greatly appreciated.
    Ideally I would want a program to do both full/half steps, forward/reverse, have speed control and be able to control the number of steps.

    Hi Wef,
    I would need to know more information about the devices in order to assist you.
    What inputs does the stepper motor controller require and what hardware are you using to supply the required signals to the motor.
    Best regards,
    Stephen C
    Applications Engineer

  • How do I get rid of the Microsoft Setup Assistant loop? I migrated my software/documents from another laptop so don't have the disk to reinstall. Please help! Can't open any Microsoft Office software, like Word, and stuck in a loop?

    I migrated my software/documents from another laptop so don't have the disk to reinstall. Please help! Can't open any Microsoft Office software, like Word (for 2008), and stuck in a loop?
    Whenever I select Word Microsoft Setup Assistant appears, asks for feedback, then after selecting okay (both on saying yes or no to feedback) goes on to a registration page. When I click on this it says I've already registered so I just click okay, and then move on to a update page. After this, if I click on Word, the process repeats itself.
    As I said, I don't have the disk to reinstall, and can't find the Office Settings to delete as many pages have suggested I should try. Safe Boot restarting also hasn't worked... Really stuck and need Word very soon for work.
    If you can help, that would be great, and feel free to ask any questions about the situation as I'm not an expert here.
    Cheers,
    Jack

    First, export your contact from iCloud.com and save them on your computer in a safe spot some where (like you desktop).  Use this to help you do this: http://support.apple.com/kb/PH3606
    Next, on both of your devices, go to Settings > iCloud and turn on contacts and select Merge. Then turn off contacts and select 'Delete form my [device]' when prompted.
    Now go back to iCloud.com and select a contact (yes they will all be messed up again) and select Command+A on a Mac or Control+A on a PC to select all of the contacts.  Tap the delete key on your keyboard (or right click /control click a contact and select delete).
    You iPhone, iPad and iCloud.com should not be empty for contacts.
    Go back to Settings > iCloud on both devices and turn on contacts again (you should not see merge this time).
    Next, go back to iCloud.com and import your contacts (those exported .vcards).  You can either drag and drop them into the empty contacts list in your web browser, or you can use the gear icon to import.
    You cleaned up contacts should import correctly into iCloud.com and sync to both of your devices.
    Good luck.

  • How to make my waveform in control and design simulation run continuously?

    Hi all, i m a begineer of Labview and have some question to ask.
    I am using the Labview to design and implement a controller for FOPTD system, but i found that the waveform in the "control and simulation loop" is not running continuously. I mean it keep repeat in the same graph from 0 to 10second. Is there any approach to make it run continuously? 
    Thankyou very much.
    Solved!
    Go to Solution.
    Attachments:
    Project 1.png ‏12 KB
    Project 2.png ‏18 KB

    Well, my suggestion then is to do the following: change final time from Inf back to 10 s (or whatever number that capture the whole simulation) and do a while loop around the Control and Simulation Loop with a "wait until next ms" function to give you time to react and change parameters, like this below. This would make LabVIEW to do the whole simulation, wait for 1000 ms and then, run the simulation again with new parameters. If you need more time, just need to change the constant wired to the "wait until next milisecond".
    Barp - Control and Simulation Group - LabVIEW R&D - National Instruments

Maybe you are looking for

  • How do I change my default PDF viewer in Safari?

    I recently downloaded Acrobat Reader. Ever since, when I have opened PDF files on the internet, they have opened in Acrobat. How on earth do I switch the default back to Preview, or the regular Safari pdf viewer? I don't want to view my internet PDF'

  • Trying to add more photos to photo stream from albums

    Trying to add more photos to photo stream from albums in iPhoto on ipad .would like to view them on my Apple TV. I have 6 photos on the photo stream and lots more in albums but can't seem to be able to get them into the photo stream to view.

  • Slow FTP?

    I apologize if this isn't appropriate for this category. I'm new to the Mac, have had my MacBook Pro less than a year, and continue to be delighted. But I'm still new enough that I don't know where to look or whom to ask when a problem comes up. I wa

  • Chart displays real quick

    I am using buffered data acquisition and i acquire at the rate of 20,000 samples per second and i write my data to a binary file. The problem is I view my data in a chart when recording the data. The chart is too fast, I want to reduce the speed of t

  • Support Packages stack ERP HR level

    Hi, I am requesting information about what the ERP HR stack level is for the common SAP ERP 6.0 Support Package Stack level 17 which is comming out week 13, 2010? Regards, Jesper SAP Project Manager from Denmark