Re: Change type/creator
Re: Change type/creator
- Subject: Re: Change type/creator
- From: Doug McNutt <email@hidden>
- Date: Fri, 24 Sep 2004 09:39:36 -0600
At 08:30 +0200 9/22/04, Bernard Azancot wrote:
>I would like to know how to write an applet which first reads type/creator from a first dropped document file and change a second dropped file's one.
I have been using hard links to generate an AppleScript interface that is a bit different. It seemed appropriate for this job. System 10 required. Comments welcome especially regarding the linking technique.
The idea is that, after a most simple installation there are two UNIX hard links to two different functions for a single AppleScript applet. In this case one takes a dropped file and "copies" its type and creator codes into properties which stay around. After that is done dropping any number of files on the other link will install - paste - the copied attributes into the dropped files.
If you save this script as an application in a folder of its own you can then double click it to accomplish the install which makes the links.
<ftp://ftp.macnauchtan.com/Software/CopyTandC/T&C_0.1.sitx> (21 kB)
The code is adapted from this line-end adjuster for text files.
<ftp://ftp.macnauchtan.com/Software/LineEnds/FixEndsFolder.sit> (52 kB)
-- Begin script from the first URL above --
property CopyName : "CopyTandC"
property PasteName : "PasteTandC"
property newCreator : ""
property newType : ""
property basedir : ""
property appPath : ""
global myname
-- On double click
-- This is really an installer.
-- Run it once after expanding or changing directory structure.
on run
preamble()
set linklist to {CopyName, PasteName}
set setdir to "cd " & quoted form of basedir & ";" & space
-- Prepare names hard links to myself for drag and drop
repeat with alink in linklist
do shell script setdir & "ln -f " & myname & space & alink
end repeat
tell application "Finder"
-- set up icon view, font size, and sort by name
set thefolder to container of file appPath
set thewindow to a reference to container window of thefolder
set wbounds to bounds of thewindow
set item 3 of wbounds to (item 1 of wbounds) + 140
set item 4 of wbounds to (item 2 of wbounds) + 140
set bounds of thewindow to wbounds
set current view of thewindow to icon view
set icon size of icon view options of thewindow to 16
set arrangement of icon view options of thewindow to arranged by name
end tell
end run
on preamble() -- Find working directory and clicked icon
set appPath to path to me
set mynix to POSIX path of appPath
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "/"
set nodes to text items of mynix -- A blank comes first
set myname to last item of nodes
set basedir to "/"
repeat with lynn from 2 to (count items of nodes) - 1
set basedir to basedir & item lynn of nodes & "/"
end repeat
--display dialog basedir
set AppleScript's text item delimiters to tid
end preamble
-- This happens when icons are dropped onto the script in Applet form.
-- Note that finder resolves any aliases even though it delivers alis's in arglist.
on open (argList)
preamble()
if myname is CopyName then
tell application "Finder"
set newCreator to creator type of item 1 of argList -- We use the first item only without warning
set newType to file type of item 1 of argList
end tell
display dialog "type is |" & newType & "|, creator is |" & newCreator & "|" giving up after 5
end if
if myname is PasteName then
tell application "Finder"
repeat with theAlias in argList -- We will process all files dropped.
set creator type of theAlias to newCreator
set file type of theAlias to newType
end repeat
end tell
end if
end open
--
Applescript syntax is like English spelling:
Roughly, but not thoroughly, thought through.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden