Alt, CMD, Ctrl or Shift key pressed

Hi Yvan

I want to make Mac Excel version of this Add-in and I not want that the user must install any other software to have it working.
http://www.rondebruin.nl/win/addins/datepicker.htm

So if the solution from Stefank (I never see this solution) can be in a string that I can call with the VBA Macscript function then I love to try it.

A script library embedded in a script (.scptd or .app) is nether third-party nor does it require separate installation.

Hi Shane

Good morning

In VBA we must create a Script string and call it with the VBA Macscript function, for example this simple script:

http://www.rondebruin.nl/mac/mac008.htm

You see that it is a part of the VBA code

Love to try what you are talking about but like to see a script example from your solution or Stefan’s
Can you post it here or link to a page with this info.

Thanks for your reply

Can VBA run a script from a file rather than text? If so, you’d save the script as a file in temporary items and call it from there.

Hi Shane

I never try that but it is not really what I want. Will be great if it is possible and can be used then but we are not used at add-ins that have more then one file needed. I see if I can get it working to call a script file and get the answer back in the VBA from this script so my code can use the answer.

Thanks and have a nice weekend

I understand. But the user would still need just one file – the VBA script would create the temporary extra script as part of its execution.

Hi Shane

Can you point me to the script CheckModifiersKeys from Stefan or yours please

I think Stefan’s is a separate app. My script is this:

use framework “AppKit” – for NSEvent

on checkModifier:keyName
	if keyName = "option" then
		set theMask to current application's NSAlternateKeyMask as integer
	else if keyName = "control" then
		set theMask to current application's NSControlKeyMask as integer
	else if keyName = "command" then
		set theMask to current application's NSCommandKeyMask as integer
	else if keyName = "shift" then
		set theMask to current application's NSShiftKeyMask as integer
	else
		return false
	end if
	set theFlag to current application's NSEvent's modifierFlags() as integer
	if ((theFlag div theMask) mod 2) = 0 then
		return false
	else
		return true
	end if
end checkModifier:

But you’d have to save the main script as a .scptd, and then save this in a subfolder. So it is a bit complicated to set up.

Thanks Shane

I check it out this weekend/next week

No, it’s a command line tool

Apologies. Separate binary would have been better.

On reflection, the idea I suggested isn’t going to work. Saving as a temporary .scpt and inserting the library file sounds fine, but there’s a not-so-subtle problem: you can’t compile a script that uses a library without the library existing in one of the library paths at compile time.

You could try saving the library to the user’s Script Libraries folder, but that’s probably in breach of at least the spirit of your self-imposed restrictions.

It seems that the command line file may be embedded in the script’s package. Am I wrong ?
If this scheme is wrong there is always the ability to embed ASObjC Runner.app.
I already ran a script using this scheme : Lion DiskMaker.

Yvan KOENIG (VALLAURIS, France) dimanche 17 août 2014 14:42:19

Hi all

Will publish a VBA solution based on DJ’s script on my site.
It is working so it is better than nothing.

But I love to see scripts that are working,maybe I can use it ?

Hi,

I think you can cut out the do shell script by running the python script. You might need to upgrade your python setup with a download. I can’t remember what it was.

Edited: just remembered that you can run a unix python script.

Edited: also, you can check for all the modifier keys in one python script. So, you don’t need to check for each on individually.

Edited: I didn’t get why you couldn’t use Shane’s Script Library script. That should be quick.

Edited: maybe you can place an alias to the library script in the user’s Script Library. I don’t know if it would work. Still checking on these ideas.

Edited: too many ideas and not enough time. Just thought of another idea. A pepper scented car cover to keep the cats off the truck. Hope someone can help you.

Later and glGood Luck,
kel

Hi all

Hope Shane will send me a tester so I can test the script myself, I am to stupid to use/test his script because I am a VBA guy. Love to learn from you all but sometimes my head is spinning, I am sure you have that also with some VBA code.

I add this page today with a VBA example based on DJ’s script
http://www.rondebruin.nl/mac/mac031.htm

I hope with the help of you all I can add a second example that is maybe faster

Thanks

The do shell script is actually not the problem, it’s initializing the PyObjC bridge that is causing the delay. So calling directly Python or not doesn’t make much difference.

For the command the entire AppKit module is loaded which needs some time to setup (Python has an init script for a module inside a package) including a file containing 10K lines. The file contains constants, enums, constant strings and additional methods to existing cocoa classes, including the enum NSControlKeyMask = 262144.

Initially Ron was clearly looking for a solution that he can simply copy and paste into VBA’s MacScript function without any external resources needed. The MacScript function in VBA also accepts script files as it’s argument which I think Ron is trying to use now.

My personal objection would be that globally (according to statistics in July 2014) still only 62% of all macs are Mavericks. The second largest group is still Snow Leopard and not even Lion or Mountain Lion. I can see for myself that Snow Leopard is much used because some world leading multi billion dollar companies as my clients (with tens of thousands of work stations world wide), are for 90% still working on Snow Leopard. I had to downgraded some of my own machines back to Mountain Lion because Mavericks is one of the worse releases when it comes to stability. I think therefore a Mavericks only solution is narrowing down your audience, something you don’t want on a tutor site.

FWIW, ASObjC also has to load the .bridgesupport file. That does take time – but not much, and only once per process.

I agree with your conclusion, if not your polemic ;).

But if there is a problem with the time it takes for the Python one to load, and if it is considerably quicker using a Script Library (and I have no idea if that’s the case), I’m not sure that the idea of hosting two versions, one marked Mavericks-only, would be such an outrageous idea. Penalising users in the name of a common denominator seems a bit short-sighted to me.

But what would I know. Mavericks here is every bit as stable as Mountain Lion ever was, and a lot more sensible than Lion.

Totally agree. When someone has a newer system, the user should make use of the benefits.

I do believe that. It’s the backward compatibility that is my issue in Mavericks and gets me frustrated. Of course I would be lying if I said that I would have no crashes at all in ML, when it happens once or twice a day I can live with that.

Hi all

Thanks all for this very useful thread
I add an example that use a script bundle file to get the same speed as that the API in Windows thanks to Shane.

See example 2 on this page
http://www.rondebruin.nl/mac/mac031.htm

For VBA users is this page useful I think with the two examples based on DJ’s and Shane’s ideas

Thanks and have a great weekend