Updated to .NET Core

Yudi
2020-05-25 21:32:53 -03:00
parent 8d5b055d13
commit affc3f9fb5

@@ -1,15 +1,12 @@
# » OUTDATED «
# This guide will NOT work as of 2.16
Scheduling on macOS is a bit tricky, but it should work if you follow the instructions accordingly.
Make sure you already have DiscordChatExporter and Mono properly installed ([instructions here](https://github.com/Tyrrrz/DiscordChatExporter/wiki/macOS-usage-instructions)).
Make sure you already have **DiscordChatExporter.CLI** and **.NET Core** properly installed ([instructions here](https://github.com/Tyrrrz/DiscordChatExporter/wiki/macOS-usage-instructions)).
* [**1.** Creating the script](https://github.com/Tyrrrz/DiscordChatExporter/wiki/Scheduling-exports-on-macOS#1-creating-the-script)
* [**2.** Creating the .plist file](https://github.com/Tyrrrz/DiscordChatExporter/wiki/Scheduling-exports-on-macOS#2-creating-the-plist-file)
* [Exporting on System Boot/User Login](https://github.com/Tyrrrz/DiscordChatExporter/wiki/Scheduling-exports-on-macOS#exporting-on-system-bootuser-login)
* [Exporting every _n_ seconds](https://github.com/Tyrrrz/DiscordChatExporter/wiki/Scheduling-exports-on-macOS#exporting-every-n-seconds)
* [Exporting at a specific time and date](https://github.com/Tyrrrz/DiscordChatExporter/wiki/Scheduling-exports-on-macOS#exporting-at-a-specific-time-and-date)
* [Export on System Boot/User Login](https://github.com/Tyrrrz/DiscordChatExporter/wiki/Scheduling-exports-on-macOS#export-on-system-bootuser-login)
* [Export every _n_ seconds](https://github.com/Tyrrrz/DiscordChatExporter/wiki/Scheduling-exports-on-macOS#export-every-n-seconds)
* [Export at a specific time and date](https://github.com/Tyrrrz/DiscordChatExporter/wiki/Scheduling-exports-on-macOS#export-at-a-specific-time-and-date)
* [**3.** Loading the .plist into launchctl](https://github.com/Tyrrrz/DiscordChatExporter/wiki/Scheduling-exports-on-macOS#3-loading-the-plist-into-launchctl)
@@ -17,91 +14,108 @@ Make sure you already have DiscordChatExporter and Mono properly installed ([ins
**1.** Open TextEdit.app and create a new file
**2.** Convert the file to plain text in 'Format > Make Plain Text' (⇧⌘T)
**2.** Convert the file to a plain text one in 'Format > Make Plain Text' (⇧⌘T)
![](https://i.imgur.com/WXrTtXM.png)
**3.** Paste the following into the editor:
**3.** Paste the following into the text editor:
```bash
#!/bin/bash
# Info: https://github.com/Tyrrrz/DiscordChatExporter/wiki
TOKEN=<token>
TOKENTYPE=<BOT/USER>
CHANNEL=<channel>
EXEPATH=<exe>
FILENAME=<name>
EXPORTDIRECTORY=<dir>
EXPORTFORMAT=<format>
# Available export formats: PlainText, HtmlDark, HtmlLight, Csv
TOKEN=tokenhere
TOKENTYPE=bot/user
CHANNELID=channelhere
DLLFOLDER=dceFOLDERpathhere
FILENAME=filenamehere
EXPORTDIRECTORY=dirhere
EXPORTFORMAT=formathere
# Available export formats: plaintext, htmldark, htmllight, json, csv
# /\ CaSe-SeNsItIvE /\
# You can edit the export command on line 43 if you'd like to include more options like date ranges and date format. You can't use partitioning (-p) with this script.
cd $EXEPATH || exit 1
# This variable specifies in which directories the executable programs are located. Don't change it.
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/share/dotnet
if [[ "$TOKENTYPE" == "BOT" ]]; then
# This will verify if EXPORTFORMAT is valid and will set the final file extension according to it. If the format is invalid, the script will display a message and exit.
if [[ "$EXPORTFORMAT" == "plaintext" ]]; then
FORMATEXT=.txt
elif [[ "$EXPORTFORMAT" == "htmldark" ]] || [[ "$EXPORTFORMAT" == "htmllight" ]]; then
FORMATEXT=.html
elif [[ "$EXPORTFORMAT" == "json" ]]; then
FORMATEXT=.json
elif [[ "$EXPORTFORMAT" == "csv" ]]; then
FORMATEXT=.csv
else
echo "$EXPORTFORMAT - Unknown export format"
echo "Available export formats: plaintext, htmldark, htmllight, csv, json"
echo "/\ CaSe-SeNsItIvE /\\"
exit 1
fi
# This will change the script's directory to DLLPATH, if unable to do so, the script will exit.
cd $DLLFOLDER || exit 1
# This checks if you've typed "bot" on TOKENTYPE
if [[ "$TOKENTYPE" == "bot" ]]; then
ISBOTYES=-b
fi
PATH=/Library/Frameworks/Mono.framework/Versions/Current/bin/:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
# This will export your chat
dotnet DiscordChatExporter.Cli.dll export -t $TOKEN $ISBOTYES -c $CHANNELID -f $EXPORTFORMAT -o $FILENAME.tmp
mono DiscordChatExporter.Cli.exe export -t $TOKEN $ISBOTYES -c $CHANNEL -f $EXPORTFORMAT -o $FILENAME.tmp
# This sets the current time to a variable
CURRENTTIME=$(date +"%Y-%m-%d-%H-%M-%S")
if [[ "$EXPORTFORMAT" == "PlainText" ]]; then
mv "$FILENAME.tmp" "${EXPORTDIRECTORY//\"}/$FILENAME-$CURRENTTIME.txt"
elif [[ "$EXPORTFORMAT" == "HtmlDark" ]] || [[ "$EXPORTFORMAT" == "HtmlLight" ]]; then
mv "$FILENAME.tmp" "${EXPORTDIRECTORY//\"}/$FILENAME-$CURRENTTIME.html"
elif [[ "$EXPORTFORMAT" == "Csv" ]]; then
mv "$FILENAME.tmp" "${EXPORTDIRECTORY//\"}/$FILENAME-$CURRENTTIME.csv"
else
echo "$EXPORTFORMAT - Unknown export format"
echo "Available export formats: PlainText, HtmlDark, HtmlLight, Csv"
echo "/\ CaSe-SeNsItIvE /\\"
if ! rm -Rf "$FILENAME.tmp" ;then
echo "Unable to delete $PWD/$FILENAME.tmp"
fi
# This will move the .tmp file to the desired export location. If unable to do so, it will attempt to delete the .tmp file.
if ! mv "$FILENAME.tmp" "${EXPORTDIRECTORY//\"}/$FILENAME-$CURRENTTIME$FORMATEXT" ; then
echo "Unable to move $FILENAME.tmp to $EXPORTDIRECTORY/$FILENAME-$CURRENTTIME$FORMATEXT."
echo "Cleaning up..."
if ! rm -Rf "$FILENAME.tmp" ; then
echo "Unable to remove $FILENAME.tmp."
fi
exit 1
fi
exit 0
```
**4.** Replace:
**4.** Replace:<br/>
`tokenhere` with your [Token](https://github.com/Tyrrrz/DiscordChatExporter/wiki/Obtaining-Token-and-Channel-IDs)
`<token>` with your [Token](https://github.com/Tyrrrz/DiscordChatExporter/wiki/Obtaining-Token-and-Channel-IDs)
`bot/user` If it's a bot token, replace it with `bot`. If it's from a user, `user`
`<BOT/USER>` If the Token is from a bot replace it with `BOT`, if it's from a user, `USER`
`channelhere` with a [Channel ID](https://github.com/Tyrrrz/DiscordChatExporter/wiki/Obtaining-Token-and-Channel-IDs)
`<channel>` with a [Channel ID](https://github.com/Tyrrrz/DiscordChatExporter/wiki/Obtaining-Token-and-Channel-IDs)
`dceFOLDERpathhere` with DCE's **directory's path** (e.g. `/Users/user/Desktop/DiscordChatExporterFolder`, NOT `/Users/user/Desktop/DiscordChatExporterFolder/DiscordChatExporter.DLL`)
`<exe>` with the .exe **directory's path** (e.g. `/Users/user/Desktop/DiscordChatExporter`)
`filenamehere` with the exported channel's filename, without spaces
`<name>` with a filename without spaces
`dirhere` with the directory you want the files to be saved at (e.g. `/Users/user/Documents/Discord\ Exports`)
`<dir>` with the directory you want the files to be saved at, it can be different from the .exe path (e.g. `/Users/user/Documents/Discord\ Exports`)
`<format>` with one of the available export formats
`formathere` with one of the available export formats
<br/>
To quickly get file or folder paths, select the file/folder, hit Command+I (⌘I) and copy what's after `Where:`. <br/>
After copying and pasting, make sure the file/folder name is not missing. And if a folder has a space in its name, add `\` before the space, like in the example below:
To quickly get file or folder paths, select the file/folder, then hit Command+I (⌘I) and copy what's after `Where:`.<br/>
After copying and pasting, make sure the file/folder name is not missing. If a folder has spaces in its name, add `\` before the spaces, like in the example below:
* `Discord\ Exports` - Wrong ✗
* `/Users/user/Documents` - Wrong ✗
* `/Users/user/Documents/Discord Exports` - Wrong ✗
* `/Users/user/Documents/Discord\ Exports/DCE.Cli.dll` - Wrong ✗
* `/Users/user/Documents/Discord \Exports` - Wrong ✗
* `/Users/user/Documents/Discord\ Exports` - Correct ✓
* `/Users/user/Desktop/DiscordChatExporter/DiscordChatExporter.Cli.exe` - Correct ✓
* `/Users/user/Desktop/DiscordChatExporter` - Correct ✓
![](https://i.imgur.com/29u6Nyx.png)
<br/>
**5.** Save the file as `filename.sh` not `.txt`
**5.** Save the file as `filename.sh`, not `.txt`
**6.** Open Terminal.app, type `sudo chmod +x`, press the SPACE key, then drag & drop the folder into the Terminal window and hit RETURN. You may be prompted for your password, and you won't be able to see it as you type.
**6.** Open Terminal.app, type `chmod +x`, press the SPACE key, then drag & drop the `filename.sh` into the Terminal window and hit RETURN. You may be prompted for your password, and you won't be able to see it as you type.
## 2. Creating the .plist file
Open TextEdit, make a Plain Text (⇧⌘T) and then paste the following into it:
```xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
@@ -115,14 +129,13 @@ After copying and pasting, make sure the file/folder name is not missing. And if
</dict>
</plist>
```
* The `Label` string is the name of the export job, it must be something unique. Replace `local.discordchatexporter` between the `<string>` if you want to run more than one script.
* The `Label` string is the name of the export job, it must be something unique. Replace the `local.discordchatexporter` between the `<string>` with another name if you'd like to run more than one script.
* The `Program` string is the path to the script. Replace `/path/to/filename.sh` between the `<string>` to the path of the previously created script.
* The `Program` string is the path to the script. Replace `/path/to/filename.sh` between the `<string>` with the path of the previously created script.
* Replace the `REPLACEME` with the content presented in the following sections, according to <u>when</u> you want to export. <br/>
* Replace the `REPLACEME` with the content presented in the following sections according to <u>when</u> you want to export.<br/>
Save the file with the same name as the `Label`, like `local.discordchatexporter.plist` (not `.txt`) when you're finished. <br/>
Please notice that if the system is asleep, the job will be started the next time the computer wakes up.
When you're done, save the file with the same name as the `Label` and with the `.plist` extension (not `.txt`), like `local.discordchatexporter.plist`.<br/>
### Exporting on System Boot/User Login
@@ -131,7 +144,7 @@ Please notice that if the system is asleep, the job will be started the next tim
<true/>
```
### Exporting every _n_ seconds
### Export every _n_ seconds
The following example is to export every 3600 seconds (1 hour), replace the integer value with your desired time:
@@ -140,9 +153,8 @@ The following example is to export every 3600 seconds (1 hour), replace the inte
<integer>3600</integer>
```
### Exporting at a specific time and date
### Export at a specific time and date
Template:
```xml
<key>StartCalendarInterval</key>
<dict>
@@ -169,10 +181,14 @@ Key | Integer
**Sunday** - 0; **Monday** - 1; **Tuesday** - 2; **Wednesday** - 3; **Thursday** - 4; **Friday** - 5; **Saturday** - 6
Replace the template's `0`s according to the desired times.<br/>
You can delete the `<key>`s you don't want, don't forget to remove the `<integer>0</integer>` under it. Omitted keys are interpreted as wildcards, for example, if you delete the Minute key, the script will run at every minute, delete the Weekday key and it'll run at every weekday, and so on.
Replace the template's `0`s according to the desired times.
**Examples ([or skip to step 3](https://github.com/Tyrrrz/DiscordChatExporter/wiki/Scheduling-exports-on-macOS#3-loading-the-plist-into-launchctl))**
You can delete the `<key>`s you don't need, don't forget to remove the `<integer>0</integer>` under it.<br/>
Omitted keys are interpreted as wildcards, for example, if you delete the Minute key, the script will run at every minute, delete the Weekday key and it'll run at every weekday, and so on.
Be aware that if you set the day to '31', the script will only run on months that have the 31th day.
**Check the examples below ([or skip to step 3 (loading the file)](https://github.com/Tyrrrz/DiscordChatExporter/wiki/Scheduling-exports-on-macOS#3-loading-the-plist-into-launchctl)):**
Export everyday at 5:15 PM:
@@ -198,7 +214,7 @@ Every 15 minutes of an hour (xx:15):
```
Every Sunday at midnight and every Wednesday full hour (xx:00). Notice the inclusion of `<array>` and `</array>` to enable multiple times:
Every Sunday at midnight and every Wednesday full hour (xx:00). Notice the inclusion of `<array>` and `</array>` to allow multiple values:
```xml
<key>StartCalendarInterval</key>
@@ -222,32 +238,25 @@ Every Sunday at midnight and every Wednesday full hour (xx:00). Notice the inclu
## 3. Loading the .plist into launchctl
**1.** Copy your `something.plist` file according to how you want it to run:
**1.** Copy your `filename.plist` file to one of these folders according to how you want it to run:
* `~/Library/LaunchAgents` runs as the current logged in user. Choose this if you want it to run when this user logs-in.
* `~/Library/LaunchAgents` runs as the current logged in user.
* `/Library/LaunchDaemons` runs as the system _"administrator"_ (root). Choose this if you want it to run on System Startup.
* `/Library/LaunchDaemons` runs as the system "_administrator_" (root).
**If you don't wan't to run at System Startup/User Login:**<br/>
* If macOS has a single user:
* If you want to export when the user is logged in, choose the first one.<br/>
* If you want the script to always run, choose the seconds one.<br/>
* If you want to export only when the user is logged in, choose the first one.<br/>
* If you want the script to always run on System Startup, choose the second one.<br/>
* If macOS has multiple users:
* If you want the script to run only when a certain user is logged in, choose the first one.<br/>
* If you want the script to always run, choose the second one.<br/>
* If you want the script to always run on System Startup, choose the second one.<br/>
To quickly go to these directories, open Finder and press Command+Shift+G (⌘⇧G), then paste the path into the text box.
**2.** To load the job into launchctl, in Terminal, type `launchctl load`, press SPACE, drag and drop the `.plist` into the Terminal window, hit RETURN. It won't output anything if it was successfully loaded.
**2.** To load the job into launchctl, in Terminal, type `launchctl load`, press SPACE, drag and drop the `.plist` into the Terminal window, then hit RETURN. It won't output anything if it was successfully loaded.
### Extra launchctl commands
**Force a job to run**<br/>
To run a job regardless of its conditions (time), being `local.discordchatexporter` its `Label`:
```
launchctl start local.discordchatexporter
```
**Unloading a job**
```
launchctl unload /path/to/Library/LaunchAgents/local.discordchatexporter.plist
@@ -264,5 +273,5 @@ You can also see error codes (2nd number) by running this command.
launchctl list | grep local.discordchatexporter
```
#
Further reading: [Script management with launchd in Terminal on Mac](https://support.apple.com/guide/terminal/script-management-with-launchd-apdc6c1077b-5d5d-4d35-9c19-60f2397b2369/mac).<br/>
Further reading: [Script management with launchd in Terminal on Mac](https://support.apple.com/guide/terminal/script-management-with-launchd-apdc6c1077b-5d5d-4d35-9c19-60f2397b2369/mac) and [launchd.info](https://launchd.info/).<br/>
Special thanks to [@RenanYudi](https://github.com/RenanYudi)