Jump to content

How to debug problems with applescripts


Recommended Posts

Hey everyone, noob here.  Just trying to get a handle on apple scripting and Alfred.

 

I've got a script for resizing applications, it compiles and works from AppleScript Editor.  But when I move it into Alfred, it doesn't do anything.  Even if I put a display dialog as the first line of code, it does nothing.

 

Here's my script:

 

on alfred_script(q)

-- explode function
on explode(delimiter, input)
local delimiter, input, ASTID
set ASTID to AppleScript's text item delimiters
try
set AppleScript's text item delimiters to delimiter
set input to text items of input
set AppleScript's text item delimiters to ASTID
return input --> list
on error eMsg number eNum
set AppleScript's text item delimiters to ASTID
error "Can't explode: " & eMsg number eNum
end try
end explode


--set to fullscreen function
on setToFullScreen(dimensions, app_to_change)
set x1 to item 1 of dimensions
set y1 to item 2 of dimensions
set x2 to item 3 of dimensions
set y2 to item 4 of dimensions


if app_to_change is equal to "" or app_to_change is equal to "current" then
tell current application
set the bounds of the first window to {x1, y1, x2, y2}
end tell
else
tell application app_to_change
set the bounds of the first window to {x1, y1, x2, y2}
end tell
end if
end setToFullScreen


set monitor to ""
set app_to_set to ""


try
set query_list to explode(",", query)
set monitor to first item of query_list
set app_to_set to second item of query_list
end try


if monitor is equal to "" then set monitor to "1"




-- get the dimensions of the desktop, set up few variables
tell application "Finder"
set displayAreaDimensions to bounds of window of desktop
set x1 to item 1 of displayAreaDimensions
set y1 to item 2 of displayAreaDimensions
set x2 to item 3 of displayAreaDimensions
set y2 to item 4 of displayAreaDimensions
end tell




set width to x2 - x1
set height to y2 - y1


if width is less than or equal to 1680 then


-- Handle one monitor
setToFullScreen(displayAreaDimensions, app_to_set)


else


-- Handle multiple monitors
set new_bounds to getBoundsForMonitor(monitor)
setToFullScreen(new_bounds, app_to_set)


end if




end alfred_script

So two questions, anything obvious here causing Alfred to dislike my script?  Also, and more importantly, are there log files or a way to debug what's happening with a script that Alfred ran?

 

Thanks so much and to the Alfred team ... this is a kick-ass application, really letting me automate my life!

Edited by irish.cn
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...