Write To NTFS Drives

19 11 2007

Follow the instructions here

for the last part, i could not mount the drives with

/sw/bin/ntfs-3g /dev/disk2s1 /Volumes/ntfsdrive

instead use

sudo /sw/bin/ntfs-3g /dev/disk5 /Volumes/ntfsdrive

and replace /dev/disk5 and /Volumes/ntfsdrive accordingly





Check Input As Numbers Only Using Array

18 11 2007

set numList to {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
repeat with myCounter from 1 to (length of serialNo)
set myChar to item myCounter of serialNo
if myChar is not in numList then
display dialog "Please enter numbers only." buttons {"OK"} default button 1 with icon "iconWarning"
return
end if
end repeat





Write To File As UTF-8

10 11 2007

set thePath to ":Library:Application Support:MyApp:test.txt"
write "Hello World" to file thePath as «class utf8»

If you get an Expected expression but found unknown token. (-2741) error, just change your applescript file format. Format -> File Encoding -> Western (MacRoman)





Run Applescript in Carbon

7 11 2007

Found in Apple Developer Connection

Example

SimpleRunAppleScript(
"tell application \"Finder\"\n"
" activate\n"
" select folder \"Documents\" of startup disk\n"
" open selection\n"
"end tell");





Open & Read File

7 11 2007

char filename[] = "input.txt";
ifstream inFile;
int size;
inFile.open(filename,ios::in);
if(!inFile) {
return -4;
}
size = (int) inFile.tellg();
char mySerial[size];
while(!inFile.eof()) {
inFile >> mySerial;
}
inFile.close();





Get Root Path

7 11 2007

set rootpath to path to startup disk as string
display dialog rootpath





Auto. Create & Save TextEdit File

3 11 2007

set folderpath to "Macintosh HD:Users:Phoenix:test:"
tell application "TextEdit"
set myDoc to document 1
set text of myDoc to "Hello World"
set filepath to folderpath & "hello.txt"
close myDoc saving yes saving in filepath
end tell





Minimize All Safari Windows

1 11 2007

tell application "Safari"
set allWindows to get windows
set n to count allWindows
repeat until n = 0
set miniaturized of window n to true
set n to n - 1
end repeat
end tell





Get Default Browser

1 11 2007

Does not work in Leopard

set bundleID to do shell script "defaults read com.apple.LaunchServices | grep -A5 \"http\""
if bundleID contains "com.apple.safari" then
tell application "Safari" to activate
else if bundleID contains "org.mozilla.firefox" then
tell application "Firefox" to activate
end if





Display Dialog

1 11 2007

Displays dialog with 2 buttons

display dialog "How are you?" buttons {"Good", "Sucks"} default button 1 with icon 1

Display dialog with text box
set question to display dialog "Enter your name" default answer "" buttons {"OK", "Close"} default button 1 with icon 1
set selectedButton to button returned of question
set strName to text returned of question
if selectedButton is equal to "OK" then
display dialog "Hello " & strName
end if