to convert a string into an integer

How do I do that? I want to convert a string into an integer with Applescript…

thanks

Is this too simplistic, I might be missing the point…

set myString to "12345"
myString as number

(and what am I doing wrong with the Applescript button? It doesn’t look right when I preview!)

Thanks, …

this my code :
set open_file to choose file with prompt “Choose a file containing the messages”
set file_path to open_file as string

set file_rate_size to size of the open_file
set file_rate to file_rate_size as number

I want to open a file, and from that file I want to get the size and I want to check on the size…
that size is integer right?

thanks!

Lee

I get ‘Can’t get size of alias [path to file]’

But I’ve never been able to get my head around this whole file/alias business. Sorry I can’t help more.

It’s nothing! Thanks for your thinking and help! I’m getting crazy of this topic! but I never give up and I shall find the answer! I will try that what you said!

thanks! & grtz

lee

Yes, but you won’t get that that way. ‘choose file’ returns an alias value, which identifies a file (or folder or disk) on your filesystem. To do manipulate the file/folder itself you need to use various commands supplied by Finder or by Standard Additions, passing them that alias value so they know which file to work on. Examples:

  • To get a file’s size using Standard Additions’ ‘info for’ command:
set the_file to choose file
size of (info for the_file)
  • To get the length of the text in a plain text file, use Standard Additions’ ‘read’ command to read that text into AppleScript as a string or Unicode text value, then get the length of that:
set the_file to choose file
length of (read the_file as string) -- for a MacRoman-encoded [1] text file
set the_file to choose file
length of (read the_file as «class utf8») -- for a UTF8-encoded text file
set the_file to choose file
length of (read the_file as Unicode text) -- for a UTF16-encoded text file

(Note: in the above examples, the ‘as [class]’ bit is a parameter to the ‘read’ command that tells it how to read the file, not a coercion applied to the value of variable ‘the_file’.)

  • To get the length of the text in non-plain text files (.rtf, .doc, etc.) you’ll need to open them in a suitable application and ask the application to measure their length, e.g.:
set the_file to choose file -- e.g. an RTF file
tell application "TextEdit"
	open the_file
	count characters of text of document 1
end tell

HTH

[1] Or MacCyrillic, MacJapanese, or whatever other crusty old legacy encoding your system supports - it depends on your International settings. For North Americans, western Europeans and Antipodeans it’s generally MacRoman.

p.s. To any Code Exchange and FAQ admins: feel free to nick material from this and any other posts of mine any time you like if you think there’s anything useful in 'em.

You can also just use the Finder:

set open_file to choose file with prompt "Choose a file containing the messages"

tell application "Finder" to set file_rate_size to size of the open_file

I think I was beaten to this: but anyway…

tell application "Finder"
	set open_file to choose file with prompt "Choose a file containing the messages"
	set theInfo to info for open_file
	set sizeBytes to size of theInfo as integer
end tell

the only think it does do differently is give toy the size as a whole number - instead of the “3.60855E+5” way…

The ‘tell Finder’ block is actually redundant here as you’re using Standard Additions commands only.

HTH

Thanks!

i’m going to try those solutions!

grtz