THALO.net Home    THALO.net Forums  Hop To Forum Categories  Software Talk    Useful, non-geeky AppleScripts
Go
New
Find
Notify
Tools
Reply
  
Useful, non-geeky AppleScripts
 Login/Join
 
Mockerator
Picture of BN
Posted
Courtesy of a guy named Sal, who apparently works at Apple, here’s a tip from MacNN forums on converting a pdf (such as a screen capture) to a jpg. This was provided because there’s no way to set the default for screen captures to anything but PDF.



-- the list of file types which will be processed
-- eg: {"PICT", "JPEG", "TIFF", "GIFf"}
property type_list : {"PDF "}
-- 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 : {"pdf"}

-- This droplet processes files dropped onto the applet
on open 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
process_item(this_item)
end if
end repeat
end open

-- this sub-routine processes files
on process_item(this_item)
-- NOTE that the variable this_item is a file reference in alias format
-- FILE PROCESSING STATEMENTS GOES HERE
try
tell application "Image Events"
launch
-- get the parent folder of the image file
set the parent_folder to the container of this_item
-- derive new name for the new image file
set the new_name to my add_extension(this_item, "jpg")
-- look for an existing file
if (exists file new_name of the parent_folder) then
error "A file named \"" & new_name & "\" already exists."
end if
-- open the image file
set this_image to open this_item
-- save in new file. The result is a file ref to the new file
set the new_image to save this_image ¬
as JPEG in file new_name of the parent_folder with icon
-- purge the open image data
close this_image
end tell
tell application "Finder"
-- delete the original file
delete this_item
end tell
on error error_message
display dialog error_message
end try
end process_item

on add_extension(this_file, new_extension)
set this_info to the info for this_file
set this_name to the name of this_info
set this_extension to the name extension of this_info
if this_extension is missing value then
set the default_name to this_name
else
set the default_name to ¬
text 1 thru -((length of this_extension) + 2) of this_name
end if
return (the default_name & "." & the new_extension)
end add_extension
 
Posts: 17097 | Location: The Left Coast | Registered: Sun May 04 2003Reply With QuoteReport This Post
Thalo.net's official Master-debaiter
Picture of the man in black
Posted Hide Post
FYI, that script (when saved as an application) will -replace- the PDF you drag onto it with a JPEG.

It is not going to make a JPEG from the PDF while leaving the PDF intact.

Just as a warning, in case anyone unwittingly drags an important PDF onto it while trying it out.

But it is made to do exactly that, I just thought a bit of a warning was in order, even though the code specifically says it will delete the file.

But, you can merely comment out the line:

delete this_item

Changing it instead to:
-- delete this_item

Or just delete that line altogether.

I tend to never ever make scripts that actually delete files, instead preferring to either move or rename the old or new files.

Oh, and THANKS, that's a handy script Brad.

I make a lot of screen grabs, usually to the clipboard and straight to Photoshop but if rushed I'll just dump them as big screen grabs to the desktop as PDFs...yuk.
 
Posts: 924 | Registered: Wed June 11 2003Reply With QuoteReport This Post
Mockerator
Picture of BN
Posted Hide Post
Oh, and THANKS, that's a handy script Brad.

John, I just wrote a handy one of my own. Try it out.

tell CEO "Jobs"
cut the crap
end tell
 
Posts: 17097 | Location: The Left Coast | Registered: Sun May 04 2003Reply With QuoteReport This Post
Mockerator
Picture of BN
Posted Hide Post
FYI, that script (when saved as an application) will -replace- the PDF you drag onto it with a JPEG.

It is not going to make a JPEG from the PDF while leaving the PDF intact.


Actually, it moves the original PDF to the trash. I hadn't noticed that before.
 
Posts: 17097 | Location: The Left Coast | Registered: Sun May 04 2003Reply With QuoteReport This Post
Mockerator
Picture of BN
Posted Hide Post
Here's a useful script (at least useful to me). It addresses the problem of copying files. I've found that two Column View Finder windows is the way to go. The problem is, most of the time, I find myself using one large sidebar Finder window. It's a real pain to set up two windows, stretch them out, set their views, etc. This script is customized for a 800 x 600 screen. You can change the bounds of the windows to suit your own setup.

I keep the script in the toolbar so it first closes the window the script is activated from (don't know how to script the minimize).

tell application "Finder"
activate
close Finder window 1
make new Finder window
set current view of Finder window 1 to column view
set bounds of Finder window 1 to {5, 82, 796, 335}
make new Finder window
set current view of Finder window 1 to column view
set bounds of Finder window 1 to {5, 400, 796, 595}
end tell
 
Posts: 17097 | Location: The Left Coast | Registered: Sun May 04 2003Reply With QuoteReport This Post
  Powered by Social Strata  
 

THALO.net Home    THALO.net Forums  Hop To Forum Categories  Software Talk    Useful, non-geeky AppleScripts

© 2005 THALO.net