|
|
#1 |
|
AppleScripts snippets thread
The purpose of this thread is for other people to post snippets of AppleScript code that other people might find useful.
Here's a snippet from a script I'm working on: UPDATE: I just finished it. Here's the final result: Code:
on separateItemsIntoCategories(theContent, theCategories, categoryID)
set oldDelims to AppleScript's text item delimiters
set theDelims to {}
repeat with X from 1 to count of theCategories
set delim to (item X of theCategories) & categoryID
copy delim to end of theDelims
end repeat
set AppleScript's text item delimiters to theDelims
set categorizedContent to rest of (every text item of theContent)
set AppleScript's text item delimiters to oldDelims
return categorizedContent
end separateItemsIntoCategories
For example, let's say I build a script that sorts today's meals into four categories: breakfast, lunch, dinner, and desert. I set theContent to "Breakfast: Pancakes with syrup Lunch: A tuna fish sandwich Dinner: A salmon Dessert: Brownies" I then set theCategories to {"breakfast","lunch","dinner","dessert"} and categoryID to ":" (since the items in each category follow a :.) The function gives me {" Pancakes with syrup "," A tuna fish sandwich "," A salmon"," Brownies"} It would be cool if someone could make a snippet that, if AppleScript comes across an error, will cause the script to present the error message to the developer and offer to send the whole code to a Website or something so a human or computer can look at the code and help the developer fix the issue. Perhaps, if a computer gets the code and no typos there, the computer will try to figure out what the developer wants the script to do and offer a solution.
__________________
Now available on the iPad App Store: Clean Cuisine Click here to load its App Store page. Last edited by moonman239; Jan 14, 2013 at 11:33 PM. |
|
|
|
0
|
|
|
#2 |
|
I just updated my snippet. It is much simpler and free from any flaws that I care about, one of which being that AppleScript split some text that I did not want it to split. Note: The snippet is not compatible with any version of the Mac OS older than 10.6, because OS versions prior to 10.6 do not support having multiple text item delimiters.
__________________
Now available on the iPad App Store: Clean Cuisine Click here to load its App Store page. |
|
|
|
0
|
![]() |
|
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
All times are GMT -5. The time now is 05:12 PM.






Linear Mode
