Import AppleScript methods in another AppleScript? - import

Is there a way to use defined AppleScript methods in other AppleScripts which reference the original AppleScript with something similar to import (f.e. in PHP)?
I wrote a methode to set Skype status and mood-text:
on setSkypeStatus(status, mood_text)
tell application "System Events"
set skypeRunning to count (every process whose name is "Skype")
if skypeRunning > 0 then --only set status if skype is running
tell application "Skype"
set myStatus to "SET USERSTATUS " & status
set myMood to "SET PROFILE MOOD_TEXT " & mood_text
send command myStatus script name "AppleScript"
send command myMood script name "AppleScript"
return skypeRunning
end tell
else
return skypeRunning
end if
end tell
end setSkypeStatus
now I'm searching for something like import skype_methods.scpt. Is there such a functionality. I can't something related with Google.

One way to import another script as a library is to define a property which is initialized by loading the library as a script object. You can then use the tell command to invoke the library functions.
property pSkypeLibrary : load script POSIX file "/Users/sakra/Desktop/skype_methods.scpt"
tell pSkypeLibrary
setSkypeStatus("status", "mood")
end tell

Script Foo.scpt
set theBar to "path:to:Bar.scpt" as alias
run script (theBar)
Script Bar.scpt
display dialog "Bar"
Result: A window that displays "Bar"

There is a more elegant way of doing this. You can save your skype_methods.scpt file inside a Script Libraries folder on your computer.
Depending on how you want to define the availability of this library, you use a different folder.
Place the skype_methods.scpt file inside the /Library/Script Libraries folder to make it available for all users on the computer.
Place it in the ~/Library/Script Libraries folder to make it available for a specific user only.
You can then use all the handlers in that library as follows:
property Skype : script "skype_methods"
Skype's setSkypeStatus("status","mood")
This prevents the need of numerous tell blocks when using handlers from different libraries.

You can follow this repo https://github.com/abbeycode/AppleScripts which organises its scripts into libraries
Here is an example https://github.com/abbeycode/AppleScripts/blob/master/Scripts/Download%20Chase%20Activity.applescript
property LibLoader : load script file ((path to scripts folder from user domain as text) & "Libraries:Library Loader.scpt")
property TransmissionLib : LibLoader's loadScript("Libraries:Transmission.applescript")
property GrowlLib : LibLoader's loadScript("Libraries:Growl.applescript")
property SafariLib : LibLoader's loadScript("Libraries:Safari.applescript")
property DatesLib : LibLoader's loadScript("Libraries:Dates.applescript")

Related

Roblox ModuleScript reporting Infinite yield possible on

Helping my kid learn to develop. Using Roblox as the tool.
We are in the ServerScriptService folder and in a file called OverheadRankScript. I have a line of code like this:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DataModule = require(ReplicatedStorage:WaitForChild("DataModule"))
My ModuleScript is in ReplicatedStorage folder and it is new and looks like this.
local module = {}
return module
I get the following error
Infinite yield possible on
'ReplicatedStorage:WaitForChild("DataModule")'
I copied the example from this link
https://developer.roblox.com/en-us/articles/Scope
Does ModuleScript script need to be in Replicated Storage or is Server Script Service the correct area?
Not sure what I am doing wrong should the file name be DataModule or is ModuleScript ok?
Does the variable need to change not sure the example provided in the documentation does not seem to work.
It's just a warning, but you can add a timeout to it for the warning to stop showing up.
local DataModule = require(ReplicatedStorage:WaitForChild("DataModule", 10))
The 10 is the optional timeout parameter that you can change to whatever you'd like to.
Actually what I found out was the DataModule needs to be renamed to ModuleScript. That Is the file name and it is referencing the file name. The example referenced in the link does not mention this at all. Infinite yield possible was misleading and it could not find the file.

Writing string to specific dir using chaquopy 4.0.0

I am trying a proof of concept here:
Using Chaquopy 4.0.0 (I use python 2.7.15), I am trying to write a string to file in a specific folder (getFilesDir()) using Python, then reading in via Android.
To check whether the file was written, I am checking for the file's length (see code below).
I am expecting to get any length latger than 0 (to verify that the file indeed has been written to the specific location), but I keep getting 0.
Any help would be greatly appreciated!!
main.py:
import os.path
save_path = "/data/user/0/$packageName/files/"
name_of_file = raw_input("test")
completeName = os.path.join(save_path, name_of_file+".txt")
file1 = open(completeName, "w")
toFile = raw_input("testAsWell")
file1.write(toFile)
file1.close()
OnCreate:
if (! Python.isStarted()) {
Python.start(new AndroidPlatform(this));
File file = new File(getFilesDir(), "test.txt");
Log.e("TEST", String.valueOf(file.length()));
}```
It's not clear whether you've based your app on the console example, so I'll give an answer for both cases.
If you have based your app on the console example, then the code in onCreate will run before the code in main.py, and the file won't exist the first time you start the activity. It should exist the second time: if it still doesn't, try using the Android Studio file explorer to see what's in the files directory.
If you haven't based your app on the console example, then you'll need to execute main.py manually, like this:
Python.getInstance().getModule("main");
Also, without the input UI which the console example provides, you won't be able to read anything from stdin. So you'll need to do one of the following:
Base your app on the console example; or
Replace the raw_input calls with a hard-coded file name and content; or
Create a normal Android UI with a text box or something, and get input from the user that way.

How to Load PowerShell Functions On-Demand?

In my personal PowerShell profile that loads whenever I start PowerShell, I want to include a set of functions by calling a function.
So I want to do something like this:
function loadMyFunctions{
. \MyFunctions.ps1
}
Now, in MyFunctions.ps1 I have a function:
function bobtest{
write-host "My name is Bob Newhart."
}
I am able to load the script MyFunctions.ps1, but after that is loaded I am not able to call bobtest in the console - I get the error message The term bobtest is not recognized...
However, if I just load the script outside the function then that script is loaded and I can call bobtest normally - but that means that I can't just not load MyFunctions when the profile is loaded - I have to load MyFunctions and cannot choose.
You see, I want to load the other functions on demand and not have them available until I choose.
Is there another way to do this or can it even be done?
Have a look at this page, How to Create PowerShell Modules and Manifests.
This will enable you to create a module which will have all your custom functions! Then inside of your loadMyFunctions cmdlet add Import-Module NewModuleName.
This will enable you to use your cmdlets.
Hope this Helps,
Lachlan
Best way is to use modules. But still if you want to get in some different ways , then you can try with your approach.
See the below screenshots which I have performed.
I have a function addition which simply does addition and I saved it as funct1.ps1
Now I am calling the same function from another function of the other script just using dot source without using as module and it results me properly.
Funct1.ps1
Triggered the function from another function in another script .
Hope it helps...!!!

Setting up email content in editable email notification for Jenkins jobs

I started out by writing html code in the "Default content" section but that is not meeting my requirements since all the information I want to include in the email (html) is not available.
My questions are :
How can I set an environment variable in post build actions that I can then use in the default content section ? Is that even possible ?
How can I the know the path of a file present in the workspace after the build is done. The path contains a folder that is named using timestamp and I was looking for a way to get to the build results folder for the current build easily. Is there a way ?
You can use ${ENV, var="VARNAME"} (where VARNAME is the environment variable that you want to reference) anywhere in your HTML
As for your build folder, if it's a random timestamp during the build, you can't reference it unless you save that value to a properties file and then read it with ${PROPFILE,file="FILENAME",property="PROPERTYNAME"}
If you are using Jenkins's build timestamp BUILD_ID then you can reference that as any other environment variable.

Jenkins How can i upload a text file and use it as a parameter

I have a txt file that is holding a string inside, I want to be able to use this string in one of my scripts, so I'm wondering if there is a way to set the content of the file as one of the build properties or parameters which I'll be able to use in my scripts it should be the same as using one of the build environment properties.
For example : ${JOB_NAME} which is holding the the job name, so in the same way I want to access the content of the file which is holding some value inside.
Is it possible?
You can upload a file from your computer to the workspace through the File parameter of the job.
You can use Extended Choice plugin parameter, to read value(s) from a file and display them in a dropdown/radio-button/checkbox for the user to select, dynamically, every time the build is triggered.
You can use EnvInject plugin to read value(s) from a file and inject them into the build as environment variables, so that they can be used by the rest of the build steps/scripts.
Your question is very unclear on what your are trying to do. Pick one of the 3 methods above based on what you need, or clarify your question.