jonn8
September 12, 2003, 4:50pm
#1
Someone may find this useful:
tell window 1
set the_views to views
repeat with the_view in the_views
my [color=green]rotate_view/color
set sub_views to views of the_view
repeat with the_sub_view in sub_views
my [color=green]rotate_view/color
end repeat
end repeat
end tell
on [color=green]rotate_view/color
set x to 0
repeat while x is not 360
set x to x + 20
set bounds rotation of the_view to x
end repeat
end rotate_view
–this script was automatically tagged for
–color coded syntax by Script to Markup Code
You don’t actually need to loop through all the views, maybe you just use one view and use it as a kind of cool reward for something. Or maybe not. Still, thought I’d share.
Jon
Krioni
September 12, 2003, 8:24pm
#2
Um, what application is this supposed to work with, or is this a GUI Scripting thing?
jonn8
September 12, 2003, 9:44pm
#3
Um, it’s code for any AppleScript Studio app which is why I posted it in this forum.
Jon
Krioni
September 12, 2003, 10:07pm
#4
Man - every time I follow a link from macscripter.net ’s front page (the direct links to recent topics), I end up saying something dumb, since I don’t realize I’m in another forum. Sorry.
I did the same thing Krioni, I ran Jon’s script in SE, then posted the errors I was getting, then ended up deleting my post after I noticed which forum it was in. Doh :?
jonn8
September 14, 2003, 10:40pm
#6
Here’s code you can run from SE. Just target any AS Studio app such as Finder Window Manager (cheap plug ):
using terms from application “Project Builder”
[color=red]tell[/color] [color=blue]application[/color] "Finder Window Manager"
[color=red]tell[/color] [color=blue]window[/color] 1
[color=red]set[/color] [color=green]the_views[/color] [color=red]to[/color] [color=blue]views[/color]
[color=red]repeat[/color] [color=red]with[/color] [color=green]the_view[/color] [color=red]in[/color] [color=green]the_views[/color]
[color=red]my[/color] [color=green]rotate_view[/color]([color=green]the_view[/color])
[color=red]set[/color] [color=green]sub_views[/color] [color=red]to[/color] [color=blue]views[/color] [color=red]of[/color] [color=green]the_view[/color]
[color=red]repeat[/color] [color=red]with[/color] [color=green]the_sub_view[/color] [color=red]in[/color] [color=green]sub_views[/color]
[color=red]my[/color] [color=green]rotate_view[/color]([color=green]the_sub_view[/color])
[color=red]end[/color] [color=red]repeat[/color]
[color=red]end[/color] [color=red]repeat[/color]
[color=red]end[/color] [color=red]tell[/color]
[color=red]end[/color] [color=red]tell[/color]
[color=red]on[/color] [color=green]rotate_view[/color]([color=green]the_view[/color])
[color=red]set[/color] [color=green]x[/color] [color=red]to[/color] 0
[color=red]repeat[/color] [color=red]while[/color] [color=green]x[/color] [color=red]is[/color] [color=red]not[/color] 360
[color=red]set[/color] [color=green]x[/color] [color=red]to[/color] [color=green]x[/color] + 20
[color=red]set[/color] [color=blue]bounds rotation[/color] [color=red]of[/color] [color=green]the_view[/color] [color=red]to[/color] [color=green]x[/color]
[color=red]end[/color] [color=red]repeat[/color]
[color=red]end[/color] [color=green]rotate_view[/color]
end using terms from
–this script was automatically tagged for
–color coded syntax by Script to Markup Code
Jon
Wow, that was one of the wierdest things I’ve seen in a while. It took the buttons and all the elements of FWM’s application window and rotated them within the interface for FWM. I’m impressed Jon
A while back on the AS mailing list someone started a thread about moving windows around in the Finder, here’s one example…
on DCPSNodWindow(w, nsteps) -- David Crowe, Paul Skinner et al.
set theDamping to 5
set theAmplitude to 50
set thePeriods to 10
tell application "Finder"
activate
set {xPrime, yPrime} to position of w
repeat with i from 1 to nsteps
set position of window 1 to {xPrime, yPrime + theAmplitude * (exp (-theDamping * i / nsteps)) * (sin (i * thePeriods * pi / (nsteps)))}
end repeat
set position of window 1 to {xPrime, yPrime}
end tell
end DCPSNodWindow
Pretty kewl, me thinks.
Rob
September 15, 2003, 12:17am
#8
Fun for the whole family!
– Rob
jonn8
September 15, 2003, 12:34am
#9
Definitely cool, Greg. To get it to work, though, I had to tweak as such:
tell application “Finder” to set w to Finder window 1 –make sure a Finder window is open
DCPSNodWindow (w , 50) –I had to set nsteps > 10 to make the effect perceptible
on DCPSNodWindow (w , nsteps ) – David Crowe, Paul Skinner et al.
set theDamping to 5
set theAmplitude to 50
set thePeriods to 10
tell application “Finder”
activate
set {xPrime , yPrime } to position of w
repeat with i from 1 to nsteps
set position of w to {xPrime , yPrime + theAmplitude * (exp (-theDamping * i / nsteps )) * (sin (i * thePeriods * pi / (nsteps )))}
end repeat
set position of w to {xPrime , yPrime }
end tell
end DCPSNodWindow
–this script was automatically tagged for
–color coded syntax by Script to Markup Code
Now, if we could find a way to combine the two (spin & bounce) and make them concurrent…
Jon
They had a few of them that I thought were cool…
tell application “Finder”
activate
try
set frontWindow to window 1
set {centerx , centery } to position of frontWindow
set steps to 16
set radius to 25
set angle to pi / steps
set phi to 0
repeat steps * 2 times
set phi to phi + angle
set x to centerx + radius * (cos (phi )) - radius
set y to centery + radius * (sin (phi ))
tell application “Finder”
set position of window 1 to {x , y }
end tell
end repeat
set position of window 1 to {centerx , centery }
end try
end tell
on SpiralShakeWindow (w , destination )
set numPeriods to 10 – the number of turns arouns the final point
set numberOfSteps to 40 – the number of steps for each turn
set {xFinal , yFinal } to destination – the cneter of the spiral
set stepF to 2 * pi / numberOfSteps – the step of the angle
[color=red]tell[/color] [color=blue]application[/color] "Finder"
[color=blue]activate[/color]
[color=red]set[/color] {[color=green]xPrime[/color], [color=green]yPrime[/color]} [color=red]to[/color] [color=blue]position[/color] [color=red]of[/color] [color=green]w[/color]
[color=red]set[/color] [color=green]theta[/color] [color=red]to[/color] [color=blue]atan[/color] (([color=green]yPrime[/color] - [color=green]yFinal[/color]) / ([color=green]xPrime[/color] - [color=green]xFinal[/color]))
[color=red]if[/color] [color=green]xFinal[/color] > [color=green]xPrime[/color] [color=red]then[/color] [color=red]set[/color] [color=green]theta[/color] [color=red]to[/color] [color=green]theta[/color] + [color=blue]pi[/color] --[color=olive] check taht we took the good angle[/color]
[color=red]repeat[/color] [color=red]with[/color] [color=green]i[/color] [color=red]from[/color] 0 [color=red]to[/color] [color=green]numberOfSteps[/color] * [color=green]numPeriods[/color]
[color=red]set[/color] [color=green]r[/color] [color=red]to[/color] [color=red]my[/color] [color=green]getDistance[/color]({[color=green]xFinal[/color], [color=green]yFinal[/color]}, {[color=green]xPrime[/color], [color=green]yPrime[/color]})
[color=red]set[/color] [color=green]theta[/color] [color=red]to[/color] [color=green]theta[/color] + [color=green]stepF[/color]
[color=red]set[/color] [color=green]newX[/color] [color=red]to[/color] [color=green]xFinal[/color] + [color=green]r[/color] * (1 - [color=green]i[/color] / ([color=green]numberOfSteps[/color] * [color=green]numPeriods[/color])) * ([color=blue]cos[/color] ([color=green]theta[/color]))
[color=red]set[/color] [color=green]newY[/color] [color=red]to[/color] [color=green]yFinal[/color] + [color=green]r[/color] * (1 - [color=green]i[/color] / ([color=green]numberOfSteps[/color] * [color=green]numPeriods[/color])) * ([color=blue]sin[/color] ([color=green]theta[/color]))
[color=red]set[/color] [color=blue]position[/color] [color=red]of[/color] [color=blue]window[/color] 1 [color=red]to[/color] {[color=green]newX[/color], [color=green]newY[/color]}
[color=red]end[/color] [color=red]repeat[/color]
[color=red]end[/color] [color=red]tell[/color]
end SpiralShakeWindow
on getDistance (centerF , pointF )
return sqrt (((item 2 of centerF ) - (item 2 of pointF )) ^ 2 + ((item 2 of centerF ) - (item 2 of pointF )) ^ 2)
end getDistance
tell application “Finder”
set w to window 1
set destination to {200, 200}
end tell
SpiralShakeWindow (w , destination )
You play with the math to get differnet affects.
If my memory serves me well, I think the mighty Jean-Baptiste LE STANG had some input about these window shake thingies. It was a fun thread that I would enjoy seeing again
on SpiralShakeWindow (w , destination )
set numPeriods to 10 – the number of turns arouns the final point
set numberOfSteps to 40 – the number of steps for each turn
set {xFinal , yFinal } to destination – the cneter of the spiral
set stepF to 2 * pi / numberOfSteps – the step of the angle
tell application “Finder”
activate
set {xPrime , yPrime } to position of w
set theta to atan ((yPrime - yFinal ) / (xPrime - xFinal ))
if xFinal > xPrime then set theta to theta + pi – check taht we took the good angle
repeat with i from 0 to numberOfSteps * numPeriods
set r to my getDistance ({xFinal , yFinal }, {xPrime , yPrime })
set theta to theta + stepF
set newX to xFinal + r * (1 - i / (numberOfSteps * numPeriods )) * (cos (theta ))
set newY to yFinal + r * (1 - i / (numberOfSteps * numPeriods )) * (sin (theta ))
set position of window 1 to {newX , newY }
end repeat
end tell
end SpiralShakeWindow
on getDistance (centerF , pointF )
return sqrt (((item 2 of centerF ) - (item 2 of pointF )) ^ 2 + ((item 2 of centerF ) - (item 2 of pointF )) ^ 2)
end getDistance
tell application “Finder”
set w to window 1
set destination to {500, 300}
end tell
SpiralShakeWindow (w , destination )
on DCPSNodWindow (w , nsteps ) – David Crowe, Paul Skinner et al.
set theDamping to 5
set theAmplitude to 50
set thePeriods to 10
tell application “Finder”
activate
set {xPrime , yPrime } to position of w
repeat with i from 1 to nsteps
set position of window 1 to {xPrime , yPrime + theAmplitude * (exp (-theDamping * i / nsteps )) * (sin (i * thePeriods * pi / (nsteps )))}
end repeat
set position of window 1 to {xPrime , yPrime }
end tell
end DCPSNodWindow
tell application “Finder” to activate
tell application “Finder” to set w to window 1
DCPSNodWindow (w , 20) – doiiiing!
BTW, if you have ever typed in the wrong password in the login window of OS X, you’ve probably seen a sideways version of this. ;¬)
AppleScript, it never ceases to amaze me!