Kaydet (Commit) d8eb8a79 authored tarafından Jack Jansen's avatar Jack Jansen

MkPluginAliases - Scripts (AppleScript and Python) to create aliases

	to PPC plugin libraries
fixfiletypes.py - Script to recursively set mac creator/type based on
	extension
üst 9f0a17b8
# This python script creates Finder aliases for all the
# dynamically-loaded modules that "live in" in a single
# shared library.
# It needs a fully functional non-dynamic python to work
# (since it creates aliases to stuff it needs itself),
# you should probably drag it onto your non-dynamic python.
#
# If you compare it to MkPluginAliases.as it also serves
# as a comparison between python and AppleScript:-)
#
# Jack Jansen, CWI, August 1995
import os
import macfs
import sys
try:
import Res
except ImportError:
print """
Res module not found, which probably means that you are trying
to execute this script with a dynamically-linked python. This will
not work, since the whole point of the script is to create aliases
for dynamically-linked python to use. Do one of the following:
- Run this script using a non-dynamic python
- Use MkPluginAliases.as (an AppleScript)
- Create the aliases by hand (see the source for a list)."""
sys.exit(1)
import EasyDialogs
goals = [
("mactcp.slb", "mactcpmodules.slb"),
("macdnr.slb", "mactcpmodules.slb"),
("AE.slb", "toolboxmodules.slb"),
("Ctl.slb", "toolboxmodules.slb"),
("Dlg.slb", "toolboxmodules.slb"),
("Evt.slb", "toolboxmodules.slb"),
("Menu.slb", "toolboxmodules.slb"),
("Qd.slb", "toolboxmodules.slb"),
("Res.slb", "toolboxmodules.slb"),
("Snd.slb", "toolboxmodules.slb"),
("Win.slb", "toolboxmodules.slb"),
("imgcolormap.slb", "imgmodules.slb"),
("imgformat.slb", "imgmodules.slb"),
("imggif.slb", "imgmodules.slb"),
("imgjpeg.slb", "imgmodules.slb"),
("imgop.slb", "imgmodules.slb"),
("imgpgm.slb", "imgmodules.slb"),
("imgppm.slb", "imgmodules.slb"),
("imgtiff.slb", "imgmodules.slb")
]
#
# Not guaranteed to be correct or stay correct (Apple doesn't tell you
# how to do this), but it seems to work.
#
def mkalias(src, dst):
"""Create a finder alias"""
srcfss = macfs.FSSpec(src)
dstfss = macfs.FSSpec(dst)
alias = srcfss.NewAlias()
srcfinfo = srcfss.GetFInfo()
Res.FSpCreateResFile(dstfss, srcfinfo.Creator, srcfinfo.Type, -1)
h = Res.FSpOpenResFile(dstfss, 3)
resource = Res.Resource(alias.data)
resource.AddResource('alis', 0, '')
Res.CloseResFile(h)
dstfinfo = dstfss.GetFInfo()
dstfinfo.Flags = dstfinfo.Flags|0x8000 # Alias flag
dstfss.SetFInfo(dstfinfo)
def main():
# Ask the user for the plugins directory
dir, ok = macfs.GetDirectory()
if not ok: sys.exit(0)
os.chdir(dir.as_pathname())
# Remove old .slb aliases and collect a list of .slb files
if EasyDialogs.AskYesNoCancel('Proceed with removing old aliases?') <= 0:
sys.exit(0)
LibFiles = []
allfiles = os.listdir(':')
for f in allfiles:
if f[-4:] == '.slb':
finfo = macfs.FSSpec(f).GetFInfo()
if finfo.Flags & 0x8000:
os.unlink(f)
else:
LibFiles.append(f)
print LibFiles
# Create the new aliases.
if EasyDialogs.AskYesNoCancel('Proceed with creating new ones?') <= 0:
sys.exit(0)
for dst, src in goals:
if src in LibFiles:
mkalias(src, dst)
else:
EasyDialogs.Message(dst+' not created: '+src+' not found')
EasyDialogs.Message('All done!')
if __name__ == '__main__':
main()
-- This AppleScript creates Finder aliases for all the
-- dynamically-loaded modules that "live in" in a single
-- shared library.
-- It needs a scriptable finder, and it may need some common
-- scripting additions (i.e. stuff that *I* happen to have:-)
--
-- If you compare it to MkPluginAliases.py it also serves
-- as a comparison between python and AppleScript:-)
--
-- Jack Jansen, CWI, August 1995
-- G is a list of {target, original} tuples
set G to {{"mactcp.slb", "mactcpmodules.slb"}}
set G to (G & {{"macdnr.slb", "mactcpmodules.slb"}})
set G to (G & {{"AE.slb", "toolboxmodules.slb"}})
set G to (G & {{"Ctl.slb", "toolboxmodules.slb"}})
set G to (G & {{"Dlg.slb", "toolboxmodules.slb"}})
set G to (G & {{"Evt.slb", "toolboxmodules.slb"}})
set G to (G & {{"Menu.slb", "toolboxmodules.slb"}})
set G to (G & {{"Qd.slb", "toolboxmodules.slb"}})
set G to (G & {{"Res.slb", "toolboxmodules.slb"}})
set G to (G & {{"Snd.slb", "toolboxmodules.slb"}})
set G to (G & {{"Win.slb", "toolboxmodules.slb"}})
set G to (G & {{"imgcolormap.slb", "imgmodules.slb"}})
set G to (G & {{"imgformat.slb", "imgmodules.slb"}})
set G to (G & {{"imggif.slb", "imgmodules.slb"}})
set G to (G & {{"imgjpeg.slb", "imgmodules.slb"}})
set G to (G & {{"imgop.slb", "imgmodules.slb"}})
set G to (G & {{"imgpgm.slb", "imgmodules.slb"}})
set G to (G & {{"imgppm.slb", "imgmodules.slb"}})
set G to (G & {{"imgtiff.slb", "imgmodules.slb"}})
-- Find the plugins directory
set Dir to choose folder with prompt "Where is the PlugIns directory?"
-- List everything there
set AllFiles to list folder Dir
-- Remove .slb aliases and remember .slb files
display dialog "About to remove old .slb aliases"
set LibFiles to {}
repeat with F in AllFiles
if F ends with ".slb" then
set fileRef to ((Dir as text) & F) as alias
set Info to info for fileRef
if alias of Info then
tell application "Finder"
move fileRef to trash
end tell
else
set LibFiles to (LibFiles & F)
end if
end if
end repeat
-- Open the folder, so we can talk to the finder about it
tell application "Finder"
set FinderName to open (Dir as alias)
end tell
-- The "real" mainloop: create the aliases
display dialog "About to create new .slb aliases"
repeat with Goal in G
set Dst to item 1 of Goal
set Src to item 2 of Goal
if LibFiles contains Src then
tell application "Finder"
set DstAlias to make alias to (((Dir as text) & Src) as alias)
set name of DstAlias to Dst
end tell
else
-- The original isn't there
display dialog "Skipping alias " & Dst & " to " & Src
end if
end repeat
display dialog "All done!"
#
# Fixfiletypes - Set mac filetypes to something sensible,
# recursively down a directory tree.
#
# It will only touch extensions it feels pretty sure about.
# This script is useful after copying files from unix.
#
# Jack Jansen, CWI, 1995.
#
import os
import macfs
import sys
list = [
('.py', 'PYTH', 'TEXT'),
('.pyc', 'PYTH', 'PYC '),
('.c', 'MPCC', 'TEXT'),
('.h', 'MPCC', 'TEXT'),
('.as', 'TEXT', 'ToyS'),
('.hqx', 'TEXT', 'BnHq')
]
def walktree(name, change):
if os.path.isfile(name):
for ext, cr, tp in list:
if name[-len(ext):] == ext:
fs = macfs.FSSpec(name)
curcrtp = fs.GetCreatorType()
if curcrtp <> (cr, tp):
if change:
fs.SetCreatorType(cr, tp)
print 'Fixed ', name
else:
print 'Wrong', curcrtp, name
elif os.path.isdir(name):
print '->', name
files = os.listdir(name)
for f in files:
walktree(os.path.join(name, f), change)
def run(change):
fss, ok = macfs.GetDirectory()
if not ok:
sys.exit(0)
walktree(fss.as_pathname(), change)
if __name__ == '__main__':
run(1)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment