ClipArt Code

From NeoWiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 05:24, 4 August 2006 (edit)
Sardisson (Talk | contribs)
m (categories)
← Previous diff
Current revision (21:22, 6 August 2006) (edit) (undo)
( | contribs)
(updating to V0.1 a3 code)
 
Line 7: Line 7:
-- this will install a folder into the 'gallery' of OO.o -- this will install a folder into the 'gallery' of OO.o
 +-- Version 0.1 a.3 -6 August 2006
on run on run
Line 17: Line 18:
end idle end idle
 +-- the list of file types which will be processed
 +-- eg: {"PICT", "JPEG", "TIFF", "GIFf"}
 +property type_list : {"ZIP"}
 +-- since file types are optional in Mac OS X,
 +-- check the name extension if there is no file type
 +-- NOTE: do not use periods (.) with the items in the name extensions list
 +-- eg: {"txt", "text", "jpg", "jpeg"}, NOT: {".txt", ".text", ".jpg", ".jpeg"}
 +property extension_list : {"zip"}
 +
 +-- This droplet processes files dropped onto the applet
 +-- checks file type, only processes ZIP files
on open names on open names
checkPref() checkPref()
- openFiles(names)+ openTheseItems(names)
- display dialog "You have installed " & names & "!"+
quit quit
end open end open
---- subroutines ---- ---- subroutines ----
 +
 +-- openTheseItems
 +-- goes through each to make sure they are .zip files
 +-- processes the zip files
 +
 +on openTheseItems(these_items)
 + repeat with i from 1 to the count of these_items
 + set this_item to item i of these_items
 + set the item_info to info for this_item
 + if (folder of the item_info is false) and ¬
 + (alias of the item_info is false) and ¬
 + ((the file type of the item_info is in the type_list) or the name extension of the item_info is in the extension_list) then
 + set theFilePath to " \"" & (POSIX path of this_item) & "\""
 + set theFileInfo to (info for this_item)
 + unzipFile(theFilePath)
 + display dialog "You have installed " & this_item & "!"
 + else
 + display dialog (this_item as text) & " is not a ZIP file"
 + end if
 + end repeat
 +
 +end openTheseItems
-- unzipFile -- unzipFile
Line 32: Line 65:
set gallery to pathToGallery() set gallery to pathToGallery()
- display dialog gallery+ --display dialog gallery
- display dialog f+ --display dialog f
- set thisscript to "unzip " & f & " -d " & gallery+ set thisscript to "unzip -o " & f & " -d " & gallery
--set rmscript to "rm -r" & gallery & "/__MACOSX" --set rmscript to "rm -r" & gallery & "/__MACOSX"
do shell script thisscript with administrator privileges do shell script thisscript with administrator privileges
Line 66: Line 99:
return m return m
end pathToGallery end pathToGallery
- 
--- openFiles 
--- taken from openoffice.org.app applescript LPGL 
--- goes through any dropped files and addes them to the gallery 
- 
-on openFiles(fileList) 
- if (count of fileList) > 0 then 
- repeat with i from 1 to the count of fileList 
- set theDocument to (item i of fileList) 
- set theFilePath to " \"" & (POSIX path of theDocument) & "\"" 
- set theFileInfo to (info for theDocument) 
- unzipFile(theFilePath) 
- end repeat 
- end if 
-end openFiles 
-- getZipNames -- getZipNames
Line 126: Line 144:
on writePref(t) on writePref(t)
- display dialog t 
set officePref2 to (((path to me) as text) & "Contents:Resources:pref.txt") set officePref2 to (((path to me) as text) & "Contents:Resources:pref.txt")
set officePref2 to officePref2 as alias set officePref2 to officePref2 as alias
Line 133: Line 150:
write t to prefFile write t to prefFile
close access officePref2 close access officePref2
 + display dialog "You have set your preference to: " & t
return true return true
end writePref end writePref
Line 150: Line 168:
end if end if
end checkPref end checkPref
 +
</pre> </pre>
[[Category:NeoOffice]][[Category:Contributing]] [[Category:NeoOffice]][[Category:Contributing]]

Current revision

(will make this pretty later - the white rabbit)

-- clipart.applescript
-- clipart

--  Created by Jacob  Haddon on 7/31/06.

-- this will install a folder into the 'gallery' of OO.o
-- Version 0.1 a.3 -6 August 2006

on run
	writePref(userPref())
	--display dialog readPref()
end run

on idle
	(* Add any idle time processing here. *)
end idle

-- the list of file types which will be processed
-- eg: {"PICT", "JPEG", "TIFF", "GIFf"}
property type_list : {"ZIP"}
-- since file types are optional in Mac OS X,
-- check the name extension if there is no file type
-- NOTE: do not use periods (.) with the items in the name extensions list
-- eg: {"txt", "text", "jpg", "jpeg"}, NOT: {".txt", ".text", ".jpg", ".jpeg"}
property extension_list : {"zip"}

-- This droplet processes files dropped onto the applet
-- checks file type, only processes ZIP files
on open names
	checkPref()
	openTheseItems(names)
	quit
end open

---- subroutines ----

-- openTheseItems
-- goes through each to make sure they are .zip files
-- processes the zip files

on openTheseItems(these_items)
	repeat with i from 1 to the count of these_items
		set this_item to item i of these_items
		set the item_info to info for this_item
		if (folder of the item_info is false) and ¬
			(alias of the item_info is false) and ¬
			((the file type of the item_info is in the type_list) or the name extension of the item_info is in the extension_list) then
			set theFilePath to " \"" & (POSIX path of this_item) & "\""
			set theFileInfo to (info for this_item)
			unzipFile(theFilePath)
			display dialog "You have installed " & this_item & "!"
		else
			display dialog (this_item as text) & " is not a ZIP file"
		end if
	end repeat
	
end openTheseItems

-- unzipFile
-- this unzips the .zip file into the gallery
-- input f  is name of .zip file
on unzipFile(f)
	
	set gallery to pathToGallery()
	--display dialog gallery
	--display dialog f
	set thisscript to "unzip -o " & f & " -d " & gallery
	--set rmscript to "rm -r" & gallery & "/__MACOSX"
	do shell script thisscript with administrator privileges
	
end unzipFile

-- pathToGallery
-- gets the path to the gallery
-- this is where the output of the unzip will go

on pathToGallery()
	-- path to neo
	-- set gallery to "/Applications/NeoOffice.app/Contents/share/gallery"
	-- path to oo.ox11
	-- set gallery to "/Applications/OpenOffice.org\\ 2.0.app/Contents/openoffice.org2.0/share/gallery"
	
	--tell application "Finder" to set j to POSIX path of (application file id "org.neooffice.neooffice" as string)
	set k to "/Contents/share/gallery"
	set l to "/Contents/openoffice.org2.0/share/gallery"
	set qq to readPref()
	if qq = "NeoOffice" then
		-- if statement to decide Neo or OO.o
		tell application "Finder" to set j to POSIX path of (application file id "org.neooffice.neooffice" as string)
		set m to quoted form of j & k -- for neo
	else if qq = "OpenOffice.org" then
		tell application "Finder" to set j to POSIX path of (application file id "org.openoffice.script" as string)
		set m to quoted form of j & l -- for oo.o
	else
		display dialog "Your Preferences are not set"
	end if
	return m
end pathToGallery

-- getZipNames
-- this gets the names of the zip files in the app

on getZipNames()
	set a to POSIX path of (path to me) as string
	--display dialog a
	set next to "Contents/Resources/zipfiles"
	set test to (do shell script "ls " & a & next as string)
	tell application "Finder" to set gallery to POSIX path of (application file id "org.neooffice.neooffice" as string)
	--display dialog gallery
end getZipNames

-- userPref
-- takes user input and returns it as a string
-- asks which office suite (Neo or OO.o) they want to use

on userPref()
	set whichOffice to {"NeoOffice", "OpenOffice.org"}
	set thisOffice to (choose from list whichOffice with prompt "Select Office Suite" without multiple selections allowed) as text
	--display dialog thisOffice
	return thisOffice as text
end userPref


-- readPref
-- read the preference stored in /contents/resources/pref.txt
-- default "none"
-- "NeoOffice" or "OpenOffice.org" after run

on readPref()
	--set officePref to (choose file with prompt "Select a file to read:" of type {"TEXT"})
	set officePref to (((path to me) as text) & "Contents:Resources:pref.txt")
	set officePref to officePref as alias
	open for access officePref
	set xx to (read officePref)
	close access officePref
	return xx
end readPref

-- writePref
-- writes the preference to /contents/resources/pref.txt
-- input is value to be written

on writePref(t)
	set officePref2 to (((path to me) as text) & "Contents:Resources:pref.txt")
	set officePref2 to officePref2 as alias
	set prefFile to open for access officePref2 with write permission
	set eof of prefFile to 0
	write t to prefFile
	close access officePref2
	display dialog "You have set your preference to: " & t
	return true
end writePref

-- checkPref
-- this checks to see if preferences have been set
-- does file say "NeoOffice" or "OpenOffice.org"?
-- yes, end, no, go to pref dialog

on checkPref()
	set y to readPref()
	if y = "NeoOffice" or y = "OpenOffice.org" then
		--display dialog "Yo!"
		return true
	else
		writePref(userPref())
	end if
end checkPref


Personal tools