• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Resize APOD Page
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Resize APOD Page


  • Subject: Resize APOD Page
  • From: Robert Poland <email@hidden>
  • Date: Tue, 28 Aug 2012 07:27:38 -0600

Hi,

If you are looking for something to look at…

This script, when an image is dropped on it, using GraphicConverter, resizes the image by adding borders so that the entire image fits on the desktop.

The not included step is that the command "Picture/Use Picture as Desktop Image" is selected manually. I do this manually in case the image needs additional resizing, especially very tall images.

(* Rescale picture to desktop - R. L. Poland - 1/21/12    5/19/12 - Added options    8/5/12 - added 'on run'    *)
-- NOTE: THIS SCRIPT MAY DEPEND ON THE SATIMAGE.OSAX
-- NOTE: THIS SCRIPT MAY DEPEND ON THE ASObjC Runner.app

on run
-- set myFolder to choose folder
tell application "GraphicConverter" to set droppedItem to file of window 1
tell me to open droppedItem as alias
end run

on open (droppedItem)
set blueGray to {"8000", "8000", "10000"}
set theColor to blueGray -- default
set black to {"0", "0", "0"}
set white to {"65535", "65535", "65535"}
set red to {"65535", "0", "0"}
set theColorList to {"Black", "blueGray", "White", "Red", "Manual"}
set topEdge to 22
set leftEdge to 0
set leftMargin to leftEdge
set rightMargin to 150 -- set to allow one column of icons
set newResolution to {300, 300}
set this_item to droppedItem
set fileInfo to info for this_item -- as text
set droppedName to name of fileInfo


tell (do shell script "/usr/sbin/system_profiler SPDisplaysDataType | grep Resolution") to set {monitor_R, monitor_B} to {word 2, word 4 as number} -- get screen size of main monitor


-- test for modifier keys down
tell application "ASObjC Runner"
set optionKeyDown to option key down of modifier keys
-- set shiftKeyDown to shift key down of modifier keys
-- set commandKeyDown to command key down of modifier keys
-- set controlKeyDown to control key down of modifier keys
end tell


tell application "System Events" to set activeProcesses to name of every process
if activeProcesses does not contain "GraphicConverter" then
repeat while activeProcesses does not contain "GraphicConverter"
tell application "System Events" to set activeProcesses to name of every process
tell application "GraphicConverter"
activate
end tell
delay 0.2
end repeat
end if


tell application "GraphicConverter"
activate
set windowName to ""
try
set windowName to name of window 1 -- check if already open
end try
if windowName does not contain droppedName then
set numberOfWindows to count window
repeat 50 times
open droppedItem as alias
if (count window) > numberOfWindows then exit repeat
delay 0.1
end repeat
end if


if optionKeyDown then -- set new margin color, if option down set new theColor color
set theChoice to choose from list theColorList default items "black" with title "Color Selection"
if theColor is false then error number -128 -- exit silently
set theChoice to item 1 of theChoice
if theChoice = "bluegray" then (* This if-then-else block will define the color value *)
set theColor to blueGray
else if theChoice = "Black" then
set theColor to black
else if theChoice = "White" then
set theColor to white
else if theChoice = "Red" then
set theColor to red
else if theChoice = "Manual" then
choose color (* Here the result is a RGB color *)
set theColor to result
end if
end if


tell window 1 -- Main window
set alpha channel to false -- remove alpha channel
set currentResolution to resolution as text -- don't do greater than 300


if currentResolution > newResolution then
repeat while resolution ≠ newResolution
change resolution to newResolution
delay 0.1 -- need time
end repeat
end if


set {pictureWidth, pictureHeight} to image dimension


if pictureHeight ≠ monitor_B then -- scale tall pictures to fit
set image dimension to {pictureWidth / (pictureHeight / monitor_B), monitor_B}
set {pictureWidth, pictureHeight} to image dimension
my newMargin(theColor, 0, 22, 0, 0) -- allow for MenuBar
-- change margins with {0, 22, 0, 0} -- allow for MenuBar
set {pictureWidth, pictureHeight} to image dimension
end if


if pictureWidth ≥ monitor_R then -- scale wide pictures to fit
set image dimension to {monitor_R, pictureHeight / (pictureWidth / monitor_R) as integer}
set {pictureWidth, pictureHeight} to image dimension
end if
delay 1 -- need time


if pictureHeight ≥ monitor_B then -- re-scale pictures to fit
set image dimension to {pictureWidth / (pictureHeight / monitor_B) as integer, monitor_B}
set {pictureWidth, pictureHeight} to image dimension
end if
delay 1 -- need time


if pictureWidth ≤ (monitor_R) then -- add theColor border to fill window
set margin to (monitor_R - pictureWidth)
if margin ≤ 300 then -- offset to left with 300 on right
set leftMargin to 0
set rightMargin to margin
else if (margin / 2) < rightMargin then -- offset to left edge with balance to right
set rightMargin to margin
set leftMargin to margin - rightMargin
else -- center
set leftMargin to margin / 2 as integer
set rightMargin to leftMargin
end if
my newMargin(theColor, leftMargin, 0, rightMargin, 0)
end if
if pictureHeight < monitor_B then -- add theColor border to fill window
set newMargin to (monitor_B - pictureHeight) / 2 as integer
my newMargin(theColor, leftMargin, newMargin, rightMargin, newMargin)
end if
end tell


show tools -- restore colors to default values
delay 0.2
tell window 1 -- Tools window
set foreground color to black
set background color to white
delay 0.4 -- need time
end tell


tell window 1 -- set image to top, left, Max size
tell application "System Events" to keystroke "0" using command down -- view @ Max size
-- try
-- set position to {leftEdge, topEdge} -- position command currently broken
-- on error
set {leftSide, topSide, rightSide, bottomSide} to bounds
set rightSide to rightSide - leftSide
set bottomSide to bottomSide - topSide + topEdge
set leftSide to leftEdge
set topSide to topEdge
set bounds to {leftSide, topSide, rightSide, bottomSide}
-- end try
end tell
end tell
beep
delay 1 -- Let beep finish
end open

on newMargin(theColor, leftMargin, topMargin, rightMargin, bottomMargin)
tell application "GraphicConverter"
show tools
delay 0.2
tell window 1 -- Tools window
set background color to theColor
delay 0.4 -- need time
end tell
tell window 1 to change margins with {leftMargin, topMargin, rightMargin, bottomMargin}
end tell
end newMargin


Robert Poland - Fort Collins, CO



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >Previous APOD Page (From: Christopher Stone <email@hidden>)
 >Re: Previous APOD Page (From: Robert Poland <email@hidden>)
 >Re: Previous APOD Page (From: Christopher Stone <email@hidden>)

  • Prev by Date: RE: InDesign CS6 Document Preferences
  • Next by Date: Set variable to contents of incoming message
  • Previous by thread: Re: Previous APOD Page
  • Next by thread: Re: Previous APOD Page
  • Index(es):
    • Date
    • Thread