I'm working on an IDE extension. One of the first things I need to be able to do is drag an icon from my new tool panel out to
the open space and create a stack when released.
This is the code I have so far. The problem is that, when I release the drag, it pops the mouse back to the start position of
the drag and creates there rather then at the end position. I suspect that is because I am not dragging onto a destination object
since I am trying to make a new stack. How can I get the release point when its not over a LiveCode object?
on mouseDown
set the dragData["text"] to empty
end mouseDown
on dragStart
set the dragImage to the id of the target
end dragStart
on dragEnd
CreateNewDBStack("New Databse Stack", "Default.sdb")
end dragEnd
command CreateNewDBStack pNewStackName, pDBname
#create stack
create stack pNewStackName
put it into tTheNewStack
set the loc of tTheNewStack to the mouseloc
set the DBPath of tTheNewStack to pDBName
#create DBscript on stack
local tScript
put "global gDBConnectionID"&cr into tScript
put "command onPreOpenStack"&cr after tScript
put " library stack ""e&"DatabaseLibrary.livecode""e&cr after tScript
put " put the DBPath of me into tDBPath"&cr after tScript
put " put databaseConnect(tDBPath) into gDBConnectionID" &cr after tScript
put "end onPreOpenStack" after tScript
set the script of tTheNewStack to tScript
end CreateNewDBStack
I don't think you're doing a real drag and drop, since you're not actually dragging an object from an app to another app (e.g. from your app to Finder or Windows Explorer). Therefore, you could use a different approach without drag and drop.
The following method creates a place holder stack. You could change the script to not delete the place holder stack and adjust its properties instead. I decided to delete the place holder stack and then run your script.
on mouseDown
set the rect of the templateStack to 0,0,100,100
set the decorations of the templateStack to "maximize,minimize,close"
set the backgroundColor of the templateStack to gray
set the blendLevel of the templateStack to 50
set the vis of the templateStack to true
set the name of the templateStack to "extPlace Holder"
set the loc of the templateStack to globalloc(the mouseLoc)
create stack
reset the templateStack
send "followMouse it" to me in 0 millisecs
end mouseDown
on followMouse theStack
put the mouseLoc into myLoc
if the mouse is down then
set the loc of theStack to globalLoc(myLoc)
send "followMouse theStack" to me in 20 millisecs
end if
end followMouse
on mouseRelease
put the mouseLoc into myLoc
if there is a stack "extPlace Holder" then delete stack "extPlace Holder"
createNewStack "New Database Stack","Default.sdb"
/*
if there is a stack "New Database Stack" then
set the loc of stack "New Database Stack" to myLoc
end if
*/
end mouseRelease
on mouseUp
put the mouseLoc into myLoc
if there is a stack "extPlace Holder" then delete stack "extPlace Holder"
end mouseUp
command createNewStack pNewStackName,pDBname
put globalLoc(the mouseloc) into myLoc
#create stack
set the vis of the templateStack to false
create stack pNewStackName
put it into tTheNewStack
set the loc of tTheNewStack to myLoc
set the DBPath of tTheNewStack to pDBName
#create DBscript on stack
local tScript
put "global gDBConnectionID"&cr into tScript
put "command onPreOpenStack"&cr after tScript
put " library stack ""e&"DatabaseLibrary.livecode""e&cr after tScript
put " put the DBPath of me into tDBPath"&cr after tScript
put " put databaseConnect(tDBPath) into gDBConnectionID" &cr after tScript
put "end onPreOpenStack" after tScript
set the script of tTheNewStack to tScript
show tTheNewStack
reset the templateStack
end createNewStack
You can use the screenMouseLoc instead of the mouseLoc.
set the loc of tTheNewStack to the screenMouseLoc
The DB stack may jump to the new location, so creating the stack invisibly then setting the visible to true at the end of your script will avoid this.
I hope this code helps you to finish your extension.
What I'm doing is creating a stack which I put the image that I drag as a background. Something similar to what the LiveCode IDE does.
Important in the _deleteDragStack command find where CreateNewDBStack is called and pass it the parameters pNewStackName, pDBname.
local sDragStack
local sStackLoc
on mouseMove
if the mouse is up then
_deleteDragStack
else if the mouse is down and there is not a sDragStack then
local tTarget
put the target into tTarget
if word 1 of tTarget is "image" then
set the destroyStack of templateStack to true
set the windowShape of templateStack to (the id of tTarget)
set the backgroundPattern of templateStack to (the id of tTarget)
set the blendLevel of templateStack to 100
set the loc of templateStack to globalLoc(the mouseLoc)
create stack
put it into sDragStack
reset templateStack
end if
else if there is sDragStack then
put globalLoc( the mouseLoc) into sStackLoc
set the loc of sDragStack to sStackLoc
set the blendLevel of sDragStack to 25
end if
pass mouseMove
end mouseMove
on mouseUp
if there is sDragStack then _deleteDragStack
end mouseUp
on mouseRelease
if there is sDragStack then _deleteDragStack
end mouseRelease
private command _deleteDragStack
if there is sDragStack then
lock messages
close sDragStack
CreateNewDBStack "Untitled"&&(random(1000))---> pNewStackName, pDBname
delete local sDragStack
unlock messages
end if
end _deleteDragStack
command CreateNewDBStack pNewStackName, pDBname
local tTheNewStack
#create stack
create stack pNewStackName
put it into tTheNewStack
set the loc of tTheNewStack to sStackLoc
set the DBPath of tTheNewStack to pDBName
#create DBscript on stack
local tScript
put "global gDBConnectionID"&cr into tScript
put "command onPreOpenStack"&cr after tScript
put " library stack ""e&"DatabaseLibrary.livecode""e&cr after tScript
put " put the DBPath of me into tDBPath"&cr after tScript
put " put databaseConnect(tDBPath) into gDBConnectionID" &cr after tScript
put "end onPreOpenStack" after tScript
set the script of tTheNewStack to tScript
end CreateNewDBStack
Related
Is there a command to clear the output portion of the Command Center? I can't find one in the user-guide -- only commands to clear a separate output area if one was defined.
I'm using NetLogo 6.1.1. in Windows 10.
I don't have a separate output section defined. The command "clear-output" doesn't clear the output portion of the Command Center.
I tried making a separate output section on the interface, and print-output and clear-output work fine on it. But without a separate area, print-output goes to the command center but clear-output doesn't clear it.
Manually pushing the "clear" button on the interface does clear it.
Am I missing something obvious?
Manually entering these commands in the command center does not clear it:
print "x"
clear-output
Doing it from inside code doesn't seem to work either
to setup
clear-all
reset-ticks
end
to go
if (ticks > 4) [stop]
print ( word "line one at tick " ticks)
if (ticks > 3 ) [clear-output]
tick
end
The answer is "you can not". You can put an "Output" on the interface tab and use output-print instead of print. This way clear-output works perfectly.
In my applescript, I am trying to select all subfolders in selected folders. The script seems to successfully select the wanted subfolders, but the each them in multiple separate windows according to their parent folder. Is there a way to force them to be open in one window (as if you expand folders in list view and cmd click to select subfolders from multiple folders)?
Thanks,
Poon
Here is the code, just in case.
tell application "Finder"
set SelectedFolders to selection
set i to 1
set NewSelection to {}
repeat with aFolder in SelectedFolders
repeat with bFolder in aFolder
copy bFolder to the end of NewSelection
end repeat
end repeat
select every item of NewSelection
end tell
You can try "set selection" instead of "select". The front Finder window will have to be in list view and the appropriate folder will have to be expanded already. Basically if what you're trying to select is not visible in the front Finder window then it will not work.
set selection to NewSelection
I do not know of a way to expand a folder programatically. However you can ensure the Finder window is in list view using this...
set current view of Finder window 1 to list view
I think what you're trying to do will prove difficult. I couldn't get it to work consistently in my brief testing. Good luck.
I wouldn't rely on this...
tell application "Finder"
set SelectedFolders to selection
if SelectedFolders = {} then return
set current view of Finder window 1 to list view
my rightArrow()
set NewSelection to {}
repeat with aFolder in SelectedFolders
set NewSelection to NewSelection & folders of aFolder
end repeat
if NewSelection ≠ {} then
set selection to NewSelection
my rightArrow()
end if
end tell
on rightArrow()
activate application "Finder"
tell application "System Events"
tell process "Finder"
key code 124
end tell
end tell
end rightArrow
I'm trying to set it so that there's no user interaction when I open up my illustrator file using applescript, but the standard:
tell application id "com.adobe.Illustrator"
activate
set user interaction level to never interact
open theFile without dialogs
doesn't work for this plugin I have installed that checks for white overprints.
If it were up to me I'd just uninstall the plugin but it's for a work pc.
I also tried clicking the button automatically (with help from Tim Joe) by using:
try
tell application "System Events"
tell process "Finder"
click button "OK" of window "Adobe Illustrator"
end tell
end tell
end try
and I've tried
tell application "System Events"
tell process "Adobe Illustrator"
keystroke return
end tell
end tell
Does anyone know a way of solving this?
below is the full code as it currently stands:
set saveLocation to ((path to desktop) as string) --place to save the files
set theFile to choose file with prompt "Choose the Illustrator file to get outlines on"
set outputFolder to choose folder with prompt "Select the output folder"
tell application "Finder" to set fileName to name of theFile
set fullPath to (saveLocation & fileName) --file path of new .ai
set fileName to (text 1 thru ((length of fileName) - 3) of fileName) --remove .ai from fileName
set olPath to text 1 thru ((length of fullPath) - 3) of fullPath & "_OL.ai" --path of outlined file
tell application id "com.adobe.Illustrator"
activate
ignoring application responses
open theFile without dialogs
end ignoring
tell application "System Events"
tell process "Adobe Illustrator"
repeat 60 times -- wait up to 60 seconds for WOPD window to appear
try
tell window "White Overprint Detector"
keystroke return
exit repeat
end tell
on error
delay 1
end try
end repeat
end tell
end tell
save current document in file fullPath as Illustrator with options {class:Illustrator save options, compatibility:Illustrator 15, font subset threshold:0.0, embed linked files:true, save multiple artboards:false} --save file to desktop
convert to paths (every text frame of current document) --convert text to paths
save current document in file olPath as Illustrator with options {class:Illustrator save options, compatibility:Illustrator 15, font subset threshold:0.0, embed linked files:true, save multiple artboards:false} --save another copy to desktop with name + _OL.ai
end tell
tell application "Finder"
set newFolder to make new folder at saveLocation with properties {name:fileName}
move fullPath to newFolder --create new folder and move both new files into it
move olPath to newFolder
set newFolderPath to (newFolder) as string
set newFolderPath to text 1 thru -2 of newFolderPath --remove the trailing ":"
tell current application --zip up the new folder
set qpp to quoted form of POSIX path of newFolderPath
do shell script "cd $(dirname " & qpp & ")
zip -r \"$(basename " & qpp & ").zip\" \"$(basename " & qpp & ")\""
end tell
set zipFile to newFolderPath & ".zip"
move zipFile to outputFolder --move .zip to output
delete newFolder --delete folder on desktop left from zipping
end tell
--prepare a notification email
set presetText to "Hello,
Files Uploaded:
" & fileName & ".zip
To access our FTP Server:
http://217.207.130.162:8080/WebInterface/login.html
To access our FTP server, log onto our website below:
Username:
Password:
Thanks,
Joe"
tell application "Mail" --open up prepared email
activate
set theMEssage to make new outgoing message with properties {visible:true, subject:fileName, content:presetText}
end tell
--open file containing usernames and passwords for the FTP
do shell script "open /Users/produser/Desktop/FTP_Users"
I tracked down and installed White Overprint Detector I could see what you mean. I had to use an older version as I only have CS3, and I saw the dialog it produces when you open a document. The following worked for me to get it to dismiss:
tell application "Adobe Illustrator" to activate
tell application "System Events"
tell process "Adobe Illustrator"
repeat 60 times -- wait up to 60 seconds for WOPD window to appear
try
tell window "White Overprint Detector"
keystroke return
exit repeat
end tell
on error
delay 1
end try
end repeat
end tell
end tell
Since my original post seemed too objective to understand I will revise.
With in the tell block for illustrator look for your line that opens the file. Some commands allow with and without properties. Try applying the "without dialogs" property to look something like this.
tell application id "com.adobe.Illustrator"
open file (VariableOfFilePath) without dialogs
end tell
Update:
Two work arounds I can think of. 1) Try telling system events to tell AI to open without dialogs
tell application "system events"
tell application id "com.adobe.Illustrator"
open file (VariableOfFilePath) without dialogs
end tell
end tell
Other is just add in a bit that will just okay the prompt.
try
tell application "System Events"
tell process "Finder"
click button "Continue" of window "Adobe Illustrator"
end tell
end tell
end try
Can try just having it accept the default button.
tell application "System Events"
tell process "Finder"
keystroke return
end tell
end tell
I have an AutoHotkey script that I would like to run whenever the Windows 7 start menu orb is clicked (the button on the bottom left that brings up the menu).
I've been using MouseGetPos previously to determine when the cursor is hovering over the region, but this causes the script to be activated even when running fullscreen applications. Is there another way I can use to detect when the start menu orb is clicked? Thanks.
MouseGetPos,,, id, control
WinGetTitle, title, ahk_id %id%
WinGetClass, class, ahk_id %id%
if (title = "Start" || (class = "Shell_TrayWnd" && control = "")) {
;Do script
}
title = "Start" covers most of the orb, except for a few pixels at the corners.
class = "Shell_TrayWnd" refers to the entire taskbar, but only the few pixels around the orb do not have a value for control.
This should cover the entire region where normally clicking would bring out the Windows menu.
I have a simple Applescript that takes a number of images in a folder that you select and then mirror images the images using Graphic Converter. This script will run if I place it in a new AS file; however, if I try to run it a second time I get the following error "Can't get window 1 of application "GraphicConverter". Invalid index."
This script always ran on OSX 10.6
I'm running OSX 10.7.4 and Graphic Converter 8.1 (latest version).
Here is the script
tell application "Finder"
activate
set loopFinish1 to 0
set pathName to (choose folder with prompt "Choose Folder Containing Images")
set fileList1 to every file of folder pathName
set loopFinish1 to count of items of fileList1
end tell
tell application "GraphicConverter"
activate
repeat with i from 1 to loopFinish1
set currentFile to item i of fileList1
open currentFile as alias
mirror window 1 in horizontal
close window 1 saving yes
end repeat
end tell
This is driving me crazy!
GraphicConverter has other windows (visible and invisible), it's preferable to use the document to get the right window.
Also, perhaps the image doesn't open, so no window, use a try block.
activate
set pathName to (choose folder with prompt "Choose Folder Containing Images")
tell application "Finder" to set fileList1 to (document files of folder pathName) as alias list
tell application "GraphicConverter"
activate
repeat with tFile in fileList1
set currentDoc to open tFile
set CurrWindow to (first window whose its document is currentDoc)
mirror CurrWindow in horizontal
close currentDoc saving yes
end repeat
end tell