Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jul 12, 2007, 02:22 PM   #1
yellow
Moderator
 
yellow's Avatar
 
Join Date: Oct 2003
Location: Portland, OR
Applescript - Losing my mind..

I've finally lost it.. I just don't understand what I've done wrong, and of course I'm under a time crunch.

Here are the basics of what I'm trying to do...

Because most of the people in this set of labs have personal Macs that don't follow our user naming schemes for AD, I am trying to create a generic mounting script that will (if the file doesn't exist) ask for the user's name and write it to file as text. Then the same script can look at the script for the user's AD username and then mount the drives/shares as appropriate using the correct username, no matter what their current actual user name is..

The issues that I keep encountering are this:

1) When the result is written to a text file, it's not straight text. It's full of control characters. So, "joe" is "^@j^@o^@e". Is there some way that I can simply output it as straight text?

2) I put in safeguards to ask what the script reads from the file always looks right. But in the portion of the script that takes the result from the file and slaps it into a variable that I use as the username in the mount portion of the script
Code:
mount volume "cifs://DOMAIN;"& _placeUsername_ &";share.domain.edu/share$"
never populates. And when I use the same variable to try and open the user's home folder, it doesn't work (well, it works maybe 1 in 50 times, oddly).

Code:
set mountHome to make new Finder window to folder _placeUsername_ of disk "SHARE$"
			set current view of mountHome to list view
BUT, before each of these actions, I ask for the output of the variable and it always works. And when I look at the event logs in Applescript, it's always right.

Code:
mount volume "cifs://DOMAIN;joe@share.domain.edu/share$"
	make new Finder window to folder "joe" of disk "SHARE$"
Finally.. as a test, I edited the file with a text editor and simply changed it to "joe".. and what do you know, it works. Sort of.. there appears to be some sort of carriage return/newline, invisible to me. Because the event log outputs like this:

Code:
mount volume "cifs://DOMAIN;joe
@share.domain.edu/share$"
		file "SHARE$:"
	list disks
		{"Hanso", "Others", "Losties", "Dharma", "Network", "SHARE$"}
	display dialog "(view2) got username from file created: joe
"
		{button returned:"OK"}
	make new Finder window to folder "joe
" of disk "IMMU_HOME$"

Soooo.. Just what am I hoping that you can you, more knowledgeable folks, can help me with?

Can I write straight text to a file from Applescript? No control characters?
Am I supposed to be writing as Unicode?
Do you see a way around my problem here?
yellow is offline   0 Reply With Quote
Old Jul 12, 2007, 02:35 PM   #2
iMeowbot
macrumors 601
 
iMeowbot's Avatar
 
Join Date: Aug 2003
Quote:
So, "joe" is "^@j^@o^@e".
All righty ^@ is nul, so it looks like you're getting wide characters when you're expecting to work with 8-bit characters in your commands. You might try dropping the Unicode part to see if that makes the trouble go away, but what does the part that collects and writes the lusername look like (or am I staring right at that part in your post and missing it)?

The extra CR is probably just an artifact of the text editor you're using.
iMeowbot is offline   0 Reply With Quote
Old Jul 12, 2007, 02:42 PM   #3
yellow
Thread Starter
Moderator
 
yellow's Avatar
 
Join Date: Oct 2003
Location: Portland, OR
It occured to me that it might be useful if you saw how I was gathering the text. (correctly so, too )

Code:
try
	alias _pathToFile  -- This is just looking for the existance of the file.
on error
	display dialog "Please enter your UserID" default answer "Enter UserID here"
	set resultOfUserID to (text returned of result)
	set fileName to (path to documents folder as string) & ".HomeMountUsername-DoNotDelete.txt"
	set fileID to open for access file fileName with write permission
	write resultOfUserID to fileID
	close access fileID
	try
I'm not using Unicode at the moment. Frankly I didn't know if using it might make this issue go away.

The CR problem appeared when I use vi or pico. But when I "more" the file, it doesn't appear at all.

Last edited by yellow; Jul 12, 2007 at 02:49 PM.
yellow is offline   0 Reply With Quote
Old Jul 12, 2007, 02:55 PM   #4
iMeowbot
macrumors 601
 
iMeowbot's Avatar
 
Join Date: Aug 2003
Try:

write resultOfUserID as string to fileID
iMeowbot is offline   0 Reply With Quote
Old Jul 12, 2007, 03:00 PM   #5
yellow
Thread Starter
Moderator
 
yellow's Avatar
 
Join Date: Oct 2003
Location: Portland, OR
You are the best. Best, best, best. I'll throw a robotic mouse for you anytime.
yellow is offline   0 Reply With Quote
Old Jul 12, 2007, 03:39 PM   #6
iMeowbot
macrumors 601
 
iMeowbot's Avatar
 
Join Date: Aug 2003
Yay. The similarities between AppleScript and INTERCAL are too many to be mere coincidence, aren't they?
iMeowbot is offline   0 Reply With Quote
Old Jul 12, 2007, 03:53 PM   #7
yellow
Thread Starter
Moderator
 
yellow's Avatar
 
Join Date: Oct 2003
Location: Portland, OR
INTERCAL (wikipedia to the resuce)... it strikes me as a programming language as written by Terry Pratchett!

Or perhaps Doug Adams.. but I just finished re-re-reading a TP book, so I have Pratchett on the brain.
Hopefully this Cipro will clear that up.

Last edited by yellow; Jul 13, 2007 at 10:16 AM.
yellow is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
AppleScript: How do I save multiple Excel sheets to one pdf using Applescript sbtaylor1 Mac Programming 0 Oct 28, 2013 11:38 PM
AppleScript: How do I save multiple Excel sheets to one pdf using Applescript sbtaylor1 Mac Applications and Mac App Store 0 Oct 28, 2013 11:32 PM
Who in their right mind..... whoknows87 Politics, Religion, Social Issues 2 Sep 16, 2012 06:39 PM
Mind of its own! hasa619 iOS 6 15 Jul 20, 2012 02:16 PM

Forum Jump

All times are GMT -5. The time now is 07:00 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC