Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > MAking file icons and types in AppleScript Studio

MAking file icons and types in AppleScript Studio
Thread Tools
Mac Elite
Join Date: Sep 2000
Location: 'round the corner
Status: Offline
Reply With Quote
Aug 18, 2002, 02:34 PM
 
Using AppleScript, I want to set the icon image of a file, and also make the file creator of it mine...how ...okhay...i just want to set the icon image of a file..thanks!

WAIT: Could i just set the file type and file creator, and then from that, in my program make a document type?

this is for gurgel doll: I made it so you can save the thing and then will be able to re-open it to view other people's dolls.
http://www.versiontracker.com/morein...&db=macosx
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Aug 19, 2002, 03:58 AM
 
Well, you can set file types and creators like so:
Code:
tell application "Finder" set file type of (* your file *) to (* whatever *) set creator type of (* your file *) to (* whatever else *) end tell
You can also set the icon with "set icon...", but a document type sounds like a better solution.

[EDIT:] I take it back. Setting icons via AppleScript doesn't seem to work as of 10.1.5. How strange. I could've sworn it worked before. Must've been in OS 9. Oh well, hopefully you can get by with a standard icon. (If not, I suppose you could try using IconFamily.)
(Last edited by Chuckit; Aug 19, 2002 at 04:25 AM. )
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
Mac Elite
Join Date: Sep 2000
Location: 'round the corner
Status: Offline
Reply With Quote
Aug 19, 2002, 12:15 PM
 
Code:
copy false to append_data copy dollName & return & dollFur & return & dollEye & return & dollAge & return & dollStyle to this_data set the target_file to (choose file name with prompt "Please choose where to save the doll file" default name dollName & "'s File.gdol") log "l" set the target_file to the target_file as text set the open_target_file to ¬ open for access file target_file with write permission if append_data is false then ¬ set eof of the open_target_file to 0 log "n" write this_data to the open_target_file starting at eof close access the open_target_file log "m" tell application "Finder" activate set the creator type of target_file to "GDPF" end tell log "v" return true
this is not working for me!
     
Mac Elite
Join Date: Oct 2000
Status: Offline
Reply With Quote
Aug 19, 2002, 03:17 PM
 
Originally posted by Nebagakid:
copy false to append_data
copy dollName & return & dollFur & return & dollEye & return & dollAge & return & dollStyle to this_data
set the target_file to (choose file name with prompt "Please choose where to save the doll file" default name dollName & "'s File.gdol")
log "l"
set the target_file to the target_file as text
set the open_target_file to ¬
__open for access file target_file with write permission
if append_data is false then ¬
__set eof of the open_target_file to 0

log "n"
write this_data to the open_target_file starting at eof
close access the open_target_file
log "m"
tell application "Finder"
__activate
__set the creator type of target_file to "GDPF"
end tell
log "v"
return true

this is not working for me!
Note that you change the file returned by "choose file name" into text. And then later you have "open for access file target_file with write permission" What's the point of making it into text if you're just going to call it a file? Strip out that "set the target_file to the target_file as text" line, and make the "open for access file target_file with write permission" line into "open for access target_file with write permission". Also remove that activate command in the tell block. It's annoying to make the Finder pop up in the middle of the script. Here is a revised script that should work:

copy false to append_data
copy dollName & return & dollFur & return & dollEye & return & dollAge & return & dollStyle to this_data
set target_file to (choose file name with prompt "Please choose where to save the doll file" default name dollName & "'s File.gdol")

copy (open for access target_file with write permission) to open_target_file
if append_data is false then set eof of open_target_file to 0

write this_data to open_target_file starting at eof
close access open_target_file

tell application "Finder" to copy "GDPF" to target_file's creator type

return true
     
Mac Elite
Join Date: Sep 2000
Location: 'round the corner
Status: Offline
Reply With Quote
Aug 19, 2002, 08:34 PM
 
Thank you Syn(bad)notic...it worked prefectly, like peanut butter and chicken scripts..... and now, i am having a problem reading it...oh woe is me (and my limited applescript knowledge.you think i could of gotten further, oh me):
Code:
copy the contents of openedFile to theContents set opendollName to the (first line of theContents) set opendollfur to the (second line of theContents) set opendolleye to the (third line of theContents) set opendollAge to the (fourth line of theContents) set opendollWeight to the (sixth line of theContents) set opendollStyle to the (sixth line of theContents)
This is for reading the file once it is chosen through an open dialog or through someone double clicking on a file. Right now, when you try to do that, this happens (in a dialog)
Can't get line 1 of {alias "Macintosh HD:Users:nebesktop:refwe of Gw's File.gdol"}. (-1728)
well, thanks again y'all!
     
Mac Elite
Join Date: Oct 2000
Status: Offline
Reply With Quote
Aug 19, 2002, 09:45 PM
 
Well first off, dollAge, dollWeight etc... aren't even saved. Have you noticed that? And that should be "paragraph" not "line". and don't say "first paragraph" but "paragraph 1". Also, you got "line 6" twice...

Try this:

copy openedFile's contents to theContents

copy {theContents's paragraph 1, theContents's paragraph 2, theContents's paragraph 3, theContents's paragraph 4, theContents's paragraph 5, theContents's paragraph 6, theContents's paragraph 7} to {opendollName, opendollfur, opendolleye, opendollAge, opendollWeight, opendollStyle}

You should really learn Objective-C and then you can easily make XML files that are a breeze to write and read

[yourFilesContents objectForKey:@"doll name"];
     
Mac Elite
Join Date: Sep 2000
Location: 'round the corner
Status: Offline
Reply With Quote
Aug 19, 2002, 10:06 PM
 
Originally posted by Synotic:
Well first off, dollAge, dollWeight etc... aren't even saved. Have you noticed that? And that should be "paragraph" not "line". and don't say "first paragraph" but "paragraph 1". Also, you got "line 6" twice...

Try this:

copy openedFile's contents to theContents

copy {theContents's paragraph 1, theContents's paragraph 2, theContents's paragraph 3, theContents's paragraph 4, theContents's paragraph 5, theContents's paragraph 6, theContents's paragraph 7} to {opendollName, opendollfur, opendolleye, opendollAge, opendollWeight, opendollStyle}

You should really learn Objective-C and then you can easily make XML files that are a breeze to write and read

[yourFilesContents objectForKey:@"doll name"];
Syn, to the rescue again! Yeah, i wanted to use XML to being with, but i did not know how to write it. too bad for me
     
Mac Elite
Join Date: Sep 2000
Location: 'round the corner
Status: Offline
Reply With Quote
Aug 19, 2002, 10:12 PM
 
Can't get paragraph 1 of {alias "Macintosh HD:Users:nebesktop:rSSAD of Gs's File.gdol"}. (-1728)
This came up again! it is really weird.
     
Mac Elite
Join Date: Oct 2000
Status: Offline
Reply With Quote
Aug 20, 2002, 12:57 PM
 
Originally posted by Nebagakid:

This came up again! it is really weird.
It's because you're trying to get a paragraph of a file itself.. Not its contents. You're leaving out certain parts of your reading code. Can you post a little bit more? Like the actual part where you get the file then its contents?
     
Mac Elite
Join Date: Sep 2000
Location: 'round the corner
Status: Offline
Reply With Quote
Aug 20, 2002, 02:02 PM
 
Originally posted by Synotic:
It's because you're trying to get a paragraph of a file itself.. Not its contents. You're leaving out certain parts of your reading code. Can you post a little bit more? Like the actual part where you get the file then its contents?
ohkay, well, here is when someone double clicks on it and the file opens:
Code:
on open theObject open_file(theObject) end open
This part is whn someone clicks on the open button, or it is clicked by someone selecting it in the menu, the stuff in the comments are me trying to do a dialog box from a tutorial:
Code:
else if theObject is button "open button" of window "open window" then try (*tell open panel set title to "Open Gurgel Doll File" set prompt to "Open" set treat packages as directories to false set can choose directories to false set can choose files to true set allows multiple selection to false end tell if window "open window" is visible then set theWindow to "open window" else set theWindow to "home" end if set theResult to display open panel in directory "~" for file types "gdol" attached to window theWindow open_file(theResult)*) set openedFile to (choose file with prompt "Please select a Gurgel Doll File") set enabled of button "openviewdoll" of window "open window" to true open_file(openedFile)

AND here is the big code for reading the file once it is opened and the open_file is run:
Code:
on open_file(openedFile) copy openedFile's contents to theContents log "aa" try copy {theContents's paragraph 1, theContents's paragraph 2, theContents's paragraph 3, theContents's paragraph 4, theContents's paragraph 5, theContents's paragraph 6, theContents's paragraph 7} to {opendollName, opendollfur, opendolleye, opendollAge, opendollWeight, opendollStyle} on error display alert "Whoops!" as critical message "There was a problem opening the file. If it was not a GDOL file, then please choose one. Oh-key-doh-key!" & return & " -The Gurgel Doll Production Factory Head." default button "OK" end try log "bb" if opendollWeight > 50 then set opendollHeavy to "1" else set opendollHeavy to "0" end if log "cc" tell window "open window" set the contents of text field "openName" to ("Gurgel Doll's Name: " & opendollName) as string set the contents of text field "openFurcolor" to ("Fur Color: " & opendollfur) as string set the contents of text field "openEyecolor" to ("Eye Color: " & opendolleye) as string set the contents of text field "openWeight" to ("Weight: " & opendollWeight & " GUs") as string set the contents of text field "openAge" to ("Age: " & opendollAge & " Gurgel Years") as string set image of image view "dollminiHead" to load image opendollStyle & opendollfur & opendolleye & "_head.tiff" log "dd" end tell tell window "opendollView" set contents of text field "viewdollName" to opendollName as string set image of image view "dollHead" to load image opendollStyle & opendollfur & opendolleye & "_head.tiff" set image of image view "dollChest" to load image opendollStyle & opendollfur & opendollHeavy & "_chest.tiff" set image of image view "dollLegs" to load image opendollStyle & opendollfur & "_legs.tiff" end tell log "ee" end open_file

thanks a mucho!
     
Mac Elite
Join Date: Oct 2000
Status: Offline
Reply With Quote
Aug 20, 2002, 04:50 PM
 
Originally posted by Nebagakid:


ohkay, well, here is when someone double clicks on it and the file opens:
Code:
on open theObject open_file(theObject) end open
This part is whn someone clicks on the open button, or it is clicked by someone selecting it in the menu, the stuff in the comments are me trying to do a dialog box from a tutorial:
Code:
else if theObject is button "open button" of window "open window" then try (*tell open panel set title to "Open Gurgel Doll File" set prompt to "Open" set treat packages as directories to false set can choose directories to false set can choose files to true set allows multiple selection to false end tell if window "open window" is visible then set theWindow to "open window" else set theWindow to "home" end if set theResult to display open panel in directory "~" for file types "gdol" attached to window theWindow open_file(theResult)*) set openedFile to (choose file with prompt "Please select a Gurgel Doll File") set enabled of button "openviewdoll" of window "open window" to true open_file(openedFile)

AND here is the big code for reading the file once it is opened and the open_file is run:
Code:
on open_file(openedFile) copy openedFile's contents to theContents log "aa" try copy {theContents's paragraph 1, theContents's paragraph 2, theContents's paragraph 3, theContents's paragraph 4, theContents's paragraph 5, theContents's paragraph 6, theContents's paragraph 7} to {opendollName, opendollfur, opendolleye, opendollAge, opendollWeight, opendollStyle} on error display alert "Whoops!" as critical message "There was a problem opening the file. If it was not a GDOL file, then please choose one. Oh-key-doh-key!" & return & " -The Gurgel Doll Production Factory Head." default button "OK" end try log "bb" if opendollWeight > 50 then set opendollHeavy to "1" else set opendollHeavy to "0" end if log "cc" tell window "open window" set the contents of text field "openName" to ("Gurgel Doll's Name: " & opendollName) as string set the contents of text field "openFurcolor" to ("Fur Color: " & opendollfur) as string set the contents of text field "openEyecolor" to ("Eye Color: " & opendolleye) as string set the contents of text field "openWeight" to ("Weight: " & opendollWeight & " GUs") as string set the contents of text field "openAge" to ("Age: " & opendollAge & " Gurgel Years") as string set image of image view "dollminiHead" to load image opendollStyle & opendollfur & opendolleye & "_head.tiff" log "dd" end tell tell window "opendollView" set contents of text field "viewdollName" to opendollName as string set image of image view "dollHead" to load image opendollStyle & opendollfur & opendolleye & "_head.tiff" set image of image view "dollChest" to load image opendollStyle & opendollfur & opendollHeavy & "_chest.tiff" set image of image view "dollLegs" to load image opendollStyle & opendollfur & "_legs.tiff" end tell log "ee" end open_file

thanks a mucho!
Ook, I think I know the problem. First off, you do not say "contents of file" to read it. It's a little hard to explain what getting the contents does.. so I'll leave it out.. But do "read file" to read a file. Also, in the "open" handler... theObject is a list of all the files dropped on it. Even if only 1 file is dropped on it, you'll have a list with one item in it. Now what you could do in your first segment of code:

on open theObject
  open_file(theObject)
end open

Change that (which is yours unmodified) to:

on open theObject
  open_file(theObject's item 1)
end open

Keeping in mind that theObject is a list of files. And now you are passing the first file in the list to open_file. If you really wanted to get fancy you could do this:

on open theObject
  repeat with i from 1 to theObject's length
    if theObject's item i ends with ".gdol" then return open_file(theObject's item i)
  end repeat
  
  display dialog "You did not drop an appropriate .gdol file." attached to window "whatever"
end open

What it will do is, go through each file or folder that was dropped, and then it check if any of them have the .gdol extension. It will open the first file that has the extension. Note that it says "return open_file(theObject's i)" Whenever you return anything in a handler, the rest is completely cut off. For instance

on someHandler()
  do "thing #1"
  do "thing #2"
  return
  do "thing #3"
end someHandler

It will never get to the third thing because I returned before it. Now in the above example (the fancy one), it will only return and open the file if it finds a good one. If it doesn't, and the repeat loop ends (it goes through all the files), then it does the display dialog part, which tells them that there was no appropriate file. That's because it went through the entire list of dropped files and not one of them had the .gdol extension. If one did, then it would have returned an open_file, causing it never to get to the error message. Get it? Now I gave you your updated open handler... In the open_file handler... The first line:

copy openedFile's contents to theContents

Should be changed to:

copy (read openedFile) to theContents

I think that with these changes, everything will run smoothly. Also, you don't need to stick "the" in front of everything. It's pretty much useless. Hope this helps
     
Mac Elite
Join Date: Sep 2000
Location: 'round the corner
Status: Offline
Reply With Quote
Aug 20, 2002, 05:31 PM
 
this does help a lot! it does not recognize that the end of a file's name is .gdol, it just says there is a problem?

also, why does this not work:
Code:
tell open panel set title to "Open Gurgel Doll File" set prompt to "Open" set treat packages as directories to false set can choose directories to false set can choose files to true set allows multiple selection to false end tell if window "open window" is visible then set theWindow to "open window" else set theWindow to "home" end if set theResult to display open panel in directory "~" for file types "gdol" attached to window theWindow open_file(theResult)
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 06:11 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2