change and set monitor resolution...

Hello,
I’m searching free applescript code for changing monitor resolution. I would like to use it with fscommand() in Adobe Flash.
I’ve founded this interessant post : http://bbs.applescript.net/viewtopic.php?id=18397 but the link is broken:/
Thanks a lot
JP

Hello

Is it what you searched for ?

on run
	do shell script "cscreen" (*get current resolution*)
	-- do shell script "cscreen -h" (*get help (usage) *)
	--	do shell script "cscreen -v" (*get valid modes*)
	set screenResolution to the result
	--display dialog "" & screenResolution
	(*
  if screenResolution contains "1280" then
    tell application "Stickies" to quit  
    (* because im tired of having 
    to organize all my stickies every time I switch*)
    (*switch to dual [tv/mon] display*)
    do shell script "cscreen -x 800 -y 600 -r 120"
  else if screenResolution contains "800" then
    (*switch to monitor display*)
    do shell script "cscreen -x 1280 -y 1024 -r 100"
  end if
*)

Yvan KOENIG (from FRANCE jeudi 7 décembre 2006 09:45:03)

Hi Jeanphilippe,

unfortunately cscreen isn’t available any more,
but you can load it from my site : http://www.klieme.de/www/pub/cscreen.dmg

Put it in /usr/bin, with cscreen -h you get a list of all commands.

Here is a little AppleScript to read parameters of display(s) color=#FF0000[/color]:

set {maxDisplay, disParam} to cscreen(0) -- 0 = all displays, >0 = specified display

on cscreen(display)
	try
		((path to startup disk as string) & "usr:bin:cscreen") as alias
	on error
		return {false, false}
	end try
	set disParam to words of (do shell script "cscreen -l")
	set maxDisplay to item 1 of disParam as integer
	if display = 0 then
		set dispList to {}
		repeat with i from 1 to maxDisplay
			copy get_param(i, disParam) to end of dispList
		end repeat
		return {maxDisplay, dispList} -- list of max. number of displays and record(s) of parameters 
	else if display is less than or equal to maxDisplay then
		return {maxDisplay, get_param(display, disParam)}
	else
		return {false, false}
	end if
end cscreen

on get_param(DIndex, d)
	set i to 14 + ((DIndex - 1) * 5)
	set DisRecord to {DNum:item i of d, DDepth:item (i + 1) of d, DWidth:item (i + 2) of d, DHeight:item (i + 3) of d, DFreq:item (i + 4) of d}
	if DFreq of DisRecord = "0" then set DFreq of DisRecord to "TFT"
	return DisRecord
end get_param

Thanks Yvan :wink:

Stefan,
your link to cscreen.dmg is dead also :slight_smile:
In my case, i must create a cdrom with an applescript in it
BUT
if cscreen is in /usr/bin, how work the script on my CDRom ???
Must i also put cscreen on the CD ??
Thanks
JP

Sorry, here is the correct link

http://www.klieme.de/pub/cscreen.dmg

thanks a lot :wink:
and for this ? >>

Yes, if you want to create a bootable CD-ROM, cscreen must be available in /usr/bin,
this folder exists also on Apple’s boot media
But I don’t know, whether cscreen properly works, because you can’t write any data

sorry
i don’t find where is : /usr/bin ?:frowning:

This is an invisible UNIX folder.
In Finder type Shift-Cmd-G and then the path into the text field, then press return

thanks that’s run :smiley: on my mac :wink:
now, for my CDROM, my client must have cscreen in /usr/bin in his mac ?

Now I understand :slight_smile:
Yes, cscreen must be available on the target machine.
Just write a little installer, a log out or restart is not necessary

i’m newb in applescript :confused:
I don’t know write a little installer :rolleyes:

your help is very precious
thanks again :wink:

Save your script as application bundle,
open the package with the contextual menu and move the cscreen file to folder Contents:Resources
The installer can be written like this:

set theSource to quoted form of POSIX path of (((path to me) as string) & "Contents:Resources:cscreen")
do shell script "cp " & theSource & " /usr/bin" with administrator privileges

There is one disadvantage: The administrator password is required because only the admin (actually root) is able to write into /usr/bin

very very good ! ! ! thanks

arff… it’s not transparent for client :/:confused: no way against this disadvantage ???

other question :
can i write this or how ?
if screenResolution contains “1280” or “1600” or “1900” then

good news, Jeanphilippe, cscreen can be called from everywhere, and I can even change
screen resolutions on my machine without any password.

Assuming an application bundle script with cscreen in resources folder,
this changes the resolution on a second 23" display to 1600 x 1000

set cscreen to quoted form of POSIX path of (((path to me) as string) & "Contents:Resources:cscreen")
do shell script cscreen & " -s 2 -x 1600 -y 1000"

No, you must write

if screenResolution contains "1280" or screenResolution contains "1600" or screenResolution contains "1900" then

Magic ! ! !
it’s very cool :smiley:

i’ve tested that :

set cscreen to quoted form of POSIX path of (((path to me) as string) & "Contents:Resources:cscreen")
do shell script cscreen & " -s 1 -x 800 -y 600"

and work very fine ! ! ! !

but i can’t replace :
if screenResolution contains “1280” or screenResolution contains “1600” or screenResolution contains “1900” then
in this code
i’ve tried but error

thanks Stefan :slight_smile:

Interesting problem, Stefan: on my machine, the phrase "exists ((startup disk as string) & “usr:bin:cscreen”) returns true even though I do not have it installed there (I do have it - I’ve been emailing it to folks on the list who don’t for some time). I have it in my Scripts folder properly chowned and run it from there (to avoid the admin password prompt).

:lol: stupid me. Of course it doesn’t work.

¢ startup disk as string is “startup disk” !!!

¢ ((path to startup disk) as string) is the path to startup disk

Is the resolution really 1900? My 23" has 1920.
Do you get an error or it just doesn’t work?

no
ican’t replace a condition in this code :

set cscreen to quoted form of POSIX path of (((path to me) as string) & "Contents:Resources:cscreen")
do shell script cscreen & " -s 1 -x 800 -y 600"

i would like to write :

set cscreen to quoted form of POSIX path of (((path to me) as string) & "Contents:Resources:cscreen")
set screenResolution to the result
if screenResolution contains "1280" or screenResolution contains "1600" or screenResolution contains "1920" then
	do shell script cscreen & " -s 1 -x 800 -y 600"
end if

but don’t work et do nothing without error message