Blog Archives
applescript: get item number of list item
Posted by philastokes

One of the annoying ‘missing features’ in AppleScript is the lack of any way to get the item number of an item in a list.
Fortunately, since Cocoa does of course include an ‘indexOfObject’ function, we can leverage Cocoa in our AppleScript to write a nice little handler (you could add this to my list and string handlers library I posted here or just add it directly in your own scripts).
First, make sure your script or library already has two lines like these to import the Foundation framework and declare an NSArray:
use framework "Foundation"
property NSArray : a reference to current application's NSArray
Then after that add the handler:
on getIndexOfItem:anItem inList:aList
set anArray to NSArray's arrayWithArray:aList
set ind to ((anArray's indexOfObject:anItem) as number) + 1 # see note below
if ind is greater than (count of aList) then
display dialog "Item '" & anItem & "' not found in list." buttons "OK" default button "OK" with icon 2 with title "Error"
return 0
else
return ind
end if
end getIndexOfItem:inList:
You can now call the code like this:
# example
set thisList to {"I", "see", "a", "red", "door", "and", "I", "want", "to", "paint", "it", "black"}
set aNum to its getIndexOfItem:"paint" inList:thisList
(* Result --> 10 *)
if aNum is not 0 then
-- do something
end if
# Note: Remember AppleScript lists are indexed from 1, unlike Cocoa arrays which start at index 0.
Enjoy! 🙂
will Mountain Lion work on my old mac?
Posted by philastokes
If you’re wondering whether your machine can be upgraded to run OS X 10.8 Mountain Lion, you can check the full list of supported models below.
To find out which model of mac you’ve got, hold down the option key on your keyboard and select
> About This Mac
Check the ‘Model Identifier’ against this list:
MacBookPro4,1
Macmini5,3
Macmini5,2
Macmini5,1
MacBookPro5,1
MacPro4,1
MacBookPro5,2
iMac8,1
MacBookPro5,4
MacBookAir4,2
iMac11,1
iMac11,2
iMac11,3
MacBookPro8,2
MacBookPro3,1
MacPro5,1
iMac9,1
Macmini3,1
MacBookPro6,1
iMac12,2
iMac12,1
MacBook5,1
MacBook5,2
iMac10,1
MacBookPro7,1
MacBookAir4,1
MacBookPro5,3
MacBookPro6,2
MacBookPro5,5
MacBookAir3,1
MacBookAir3,2
Macmini4,1
Xserve3,1
MacBookAir2,1
MacBookPro8,1
MacBook7,1
MacBookPro8,3
iMac7,1
MacBook6,1
MacPro3,1
Of course, just because your machine’s listed, it doesn’t mean it will necessary meet all the specifications, so be sure to check the tech specs too.
🙂
Posted in Mountain Lion
Tags: able, can, compatibility, compatible, iMac, install, list, load, Mac, Macbook, macbook air, macbook pro, machines, macs, Mountain Lion, run, update, updated, upgrade, upgraded, whether, which, work
kernel_task at 103%!!
Posted by philastokes
Overheating on MacBook Pro’s is a rare problem, usually down to nothing more than new users mistakenly thinking the aluminium casing is supposed to feel cool to the touch. However, you know something’s wrong when the glass touchpad feels warm and the fan’s not even stirring…
When Finder and other apps start crashing, what might have been a small concern now starts to look like a real problem. You can try re-booting, but if you find that the reboot takes ten minutes or so and/or the keyboard doesn’t function at the login window, chances are your kernel_task process is running wild. If you’ve still got access to the desktop, you can check this in Activity Monitor, or use Terminal by typing:
>top -u
Normally, kernel_task won’t take up much more than one or two percent of CPU activity, so if you’re running at over 100% or you can’t get past the login window, its time to do a PRAM/VRAM reset.
Here’s how:
1. Power down the machine.
2. Locate the following keys on your keyboard in preparation for Step 4:
‘command’ – ‘option’ – ‘P’ – ‘R’
3. Press the ‘power on’ button.
4. Immediately – and before the grey screen appears – hold down ‘command-option-P-R’ all together.
5. Keep them held down until you’ve heard the start-up chime twice. After you release them you should hear it again, and hopefully your Mac will boot up as it should and with the kernel_task process back to normal.
Tooltip: download and run smcFanControl in your ‘Login items’ to keep an eye on your temps and fan speed in the Menubar. 😉
Have you still got this problem, or found another solution? Let us know in the Comments! 🙂
Related posts:
Why is my mac running so hot?
Why is my mac running so slow?
Also see:
Resetting the System Management Controller (SMC)
featured picture wormhole by IVIXIVIXVXII
Posted in OS X Lion, Snow Leopard
Tags: boot, cpu, disabled, frozen, hog, hogs resources, hot, kernel, kernel_task, keyboard, keyboard not functioning, list, login window, macbook pro, overheating, PRAM, processes, reset, resource hog, running, SMC, task, Terminal, top -u, VRAM, wild