Re: Viewing a jpeg
Re: Viewing a jpeg
- Subject: Re: Viewing a jpeg
- From: kai <email@hidden>
- Date: Sun, 20 Feb 2005 02:08:23 +0000
On Sat, 19 Feb 2005 09:37:33 -0600, Irwin Poche wrote:
I had considered locking the image but the problem is unlocking it.
When, or rather what would trigger, that? What I had not considered
was that the script continues to loop/idle as long as the Preview
window is open and the unlocks the image once that window is gone.
Can anyone give me an idea if this is possible? I work on a laptop,
so an actual loop isn't practice, the processor goes up to 100%, the
fan comes on, and the battery drains.
You really must stop slave-driving that poor machine, Irwin. ;-)
You might like to try inserting an idle handler into your script, which
then needs to be saved as a stay-open application. This would be a much
less processor-intensive approach. You can change the idle time by
amending the value (in seconds) returned at the end of the idle handler.
To view another photo, you just rerun the script, which you can do
quite easily by including a 'reopen' handler. (Once the applet has been
launched, you could simply reopen it from the dock, for example.)
In addition, since stay-open scripts don't quit automatically when
they've finished running, you may find some explicit quit handling
helpful.
To give you a practical example, I've thrown together the following
script, which is based loosely on your earlier description. It's a bit
rough and ready, has had scant testing - and I apologise for the
length. However, it may contain a few clues to help you get started...
-------------------------------
property myName : missing value
property checkWhenDone : true
property lockedList : {}
to hideMe()
tell application "System Events" to set process myName's visible to
false
end hideMe
to unlockFile(previewWindows)
repeat with n from 1 to count lockedList
set currItem to lockedList's item n
if currItem's name is not in previewWindows then
set currFile to currItem's file
tell application "Finder" to if currFile's locked then set
currFile's locked to false
set lockedList's item n to false
end if
end repeat
set lockedList to lockedList's records
end unlockFile
to unlockAllFiles()
repeat with currItem in lockedList
set currFile to currItem's file
tell application "Finder" to if currFile's locked then set currFile's
locked to false
end repeat
set lockedList to {}
end unlockAllFiles
to checkStatus()
tell application "System Events"
set processList to name of processes
if "Preview" is in processList then
my unlockFile(name of process "Preview"'s windows)
else
my unlockAllFiles()
if "iPhoto" is not in processList then my quitCheck()
end if
end tell
end checkStatus
to previewPic(currFile)
tell application "Finder"
if not currFile's locked then set currFile's locked to true
try
repeat with currItem in lockedList
if currItem's file is currFile then error
end repeat
set fileName to currFile's displayed name
set lockedList's end to {file:currFile, name:fileName}
end try
end tell
tell application "Preview"
activate
open currFile
end tell
tell application "System Events" to tell process "Preview" to repeat
until fileName is in name of windows
end repeat
end previewPic
to getSelection()
tell application "iPhoto"
activate
try
set currPic to (get selection)'s item 1
if (currPic's class) is not photo then error
on error
error number -128
end try
if selection is not {currPic} then select currPic
set currFile to currPic's image path
if view is not edit tab then set view to edit tab
end tell
set currFile to POSIX file currFile as alias
previewPic(currFile)
end getSelection
on quitCheck()
if checkWhenDone then
activate
try
display dialog "The applications iPhoto and Preview are no longer
running." & return & return & "Quit " & myName & " now?" buttons
{"Cancel", "Quit"} default button 2 with icon 2
on error number -128
set checkWhenDone to false
hideMe()
error number -128
end try
hideMe()
end if
tell me to quit
end quitCheck
on quit
tell application "System Events" to set processList to name of
processes
try
if "Preview" is in processList or "iPhoto" is in processList then
display dialog "Quit " & myName & " now? (Any locked files will be
unlocked - even if they are still open in Preview.)" buttons {"Quit",
"Cancel"} default button 2 with icon 0
on error number -128
hideMe()
error number -128
end try
hideMe()
unlockAllFiles()
continue quit
end quit
on idle
checkStatus()
60 -- seconds to next check
end idle
on reopen
hideMe()
getSelection()
end reopen
on run
set checkWhenDone to true
tell application "System Events" to set myName to displayed name of
(path to me)
hideMe()
getSelection()
end run
-------------------------------
---
kai
_______________________________________________
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